【问题标题】:MissingSchema: Invalid URL 'None': No schema supplied. Perhaps you meant http://None?MissingSchema:无效的 URL “无”:未提供架构。也许您的意思是 http://None?
【发布时间】:2017-11-15 11:55:21
【问题描述】:

views.py

from django.shortcuts import render
from django.http import HttpResponse
import random
import hashlib
import os
import requests

def index(request):
 """Displays the page that asks for the phone number"""
 return render(request, "verify/sms.html")

def verify(request):
 """Displays the page that asks for the verification code"""
 # if the form wasn't submitted properly, then go to index page
 try:
    phoneNumber = request.POST['phonenumber']
 except:
    return render(request, "verify/sms.html")

 verificationCode = str(random.randint(1000000, 9999999))

# the check sequence is sent to the next page to verify if the code entered is correct
 checkSequence = hashlib.sha1((verificationCode+str(os.environ.get("SEED"))).encode("utf-8")).hexdigest()

 sendVerificationCode(phoneNumber, verificationCode)
 return render(request, "verify/verification.html", {"code": checkSequence})

def checkCode(request):
"""Checks if the verification code entered is correct"""
 try:
    verificationCode = request.GET['verification']
    correctCheckSequence = request.GET['code']
 except:
    return render(request, "verify/sms.html")

# check the correct check sequence against the check sequence based on the verification code provided
 checkSequence = hashlib.sha1((verificationCode+str(os.environ.get("SEED"))).encode("utf-8")).hexdigest()
 if checkSequence == correctCheckSequence:
    return HttpResponse("1")
 else:
    return HttpResponse("0")

def sendVerificationCode(phoneNumber, verificationCode):
"""Sends the verification code to the provided phone number using TILL API"""
 if len(phoneNumber) < 10:
    return              # doesn't give the user an error message - just doesn't send the message

 TILL_URL = os.environ.get("TILL_URL")
requests.post(TILL_URL, json={"phone":[phoneNumber], "text": "Verication code: " + str(verificationCode)})

urls.py

from django.conf.urls import url, include
from . import views

urlpatterns = [
 url(r'^$', views.index, name="index"),
 url(r'^verify/$', views.verify, name="verify"),
 url(r'^checkCode/$', views.checkCode, name="checkCode")
]

models.py

from django.db import models

admin.py

from django.contrib import admin

apps.py

from django.apps import AppConfig


class VerifyConfig(AppConfig):
 name = 'verify'

创建一个短信验证应用程序。用户输入他的电话号码并发送消息以验证他的号码。

询问他的号码并按回车后不久显示错误。

引发 MissingSchema(错误) MissingSchema:无效的 URL “无”:未提供架构。也许你的意思是http://None

追溯

Internal Server Error: /verify/
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-
packages/django/core/handlers/exception.py", line 41, in inner
response = get_response(request)
File "/usr/local/lib/python2.7/dist-
packages/django/core/handlers/base.py", line 187, in _get_response
response = self.process_exception_by_middleware(e, request)
File "/usr/local/lib/python2.7/dist-
packages/django/core/handlers/base.py", line 185, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/home/tushar/Downloads/sms-verify-master/verify/views.py", line 25, in verify
sendVerificationCode(phoneNumber, verificationCode)
File "/home/tushar/Downloads/sms-verify-master/verify/views.py", line 49, in sendVerificationCode
requests.post(TILL_URL, json={"phone":[phoneNumber], "text": "Verication code: " + str(verificationCode)})
File "/usr/local/lib/python2.7/dist-packages/requests/api.py", line 109, in post
return request('post', url, data=data, json=json, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/requests/api.py", line 50, in request
response = session.request(method=method, url=url, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/requests/sessions.py", line 454, in request
prep = self.prepare_request(req)
File "/usr/local/lib/python2.7/dist-packages/requests/sessions.py", line 388, in prepare_request
hooks=merge_hooks(request.hooks, self.hooks),
File "/usr/local/lib/python2.7/dist-packages/requests/models.py", line 293, in prepare
self.prepare_url(url, params)
File "/usr/local/lib/python2.7/dist-packages/requests/models.py", line 353, in prepare_url
raise MissingSchema(error)
MissingSchema: Invalid URL 'None': No schema supplied. Perhaps you meant http://None?

【问题讨论】:

  • 您应该显示完整的回溯,并删除代码中不相关的部分。然而,似乎 TILL_URL 是无;你设置了那个环境变量吗?怎么样?
  • 我已经在 Till 上创建了账号,但是要复制哪个 url??
  • 不知道。到什么时候?
  • 把这段代码公之于众有危险吗? (假设 platform.tillmobile.com 是生产环境)

标签: python django


【解决方案1】:

TILL_URL 为“无”

要么改变这一行:

TILL_URL = os.environ.get("TILL_URL")

收件人:

TILL_URL = "https://platform.tillmobile.com/api/send/?username=<username>&api_key=<api_key>"

或在您的操作系统中设置 TILL_URL 环境变量,通过 linux 终端中的导出命令:

~ export TILL_URL="https://platform.tillmobile.com/api/send/?username=<username>&api_key=<api_key>"

他们的 API http:

https://platform.tillmobile.com/api/send/?username=<username>&api_key=<api_key>

使用您在注册后获得的仪表板中的用户名和 API 密钥:

https://platform.tillmobile.com/dashboard/

【讨论】:

  • 先生,但是在 Till 上创建帐户后要复制哪个 url??
  • 我认为您必须先在 Till mobile 注册一个帐户,然后他们才会提供。
  • 编辑了我的答案,请看。
  • 先生,它会将您带到一个页面,该页面会介绍其服务并显示 api-key。
  • 我刚刚搜索了提供商并查看了它的支持论坛。我自己也注册了,看看自己的想法对不对。 :) 不客气
猜你喜欢
  • 1970-01-01
  • 2019-10-30
  • 2021-05-05
  • 1970-01-01
  • 2022-01-23
  • 2018-06-02
  • 1970-01-01
  • 1970-01-01
  • 2019-06-16
相关资源
最近更新 更多