MissingSchema:无效的URL“无”:未提供架构。也许你的意思是http://无?

时间:2017-11-15 11:55:21

标签: python django

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?

1 个答案:

答案 0 :(得分: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命令:

~ 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/