创建用户时,没有架构提供错误,但是无论如何都会创建

时间:2019-06-26 15:22:51

标签: django oauth-2.0 django-rest-framework

我正在关注this tutorial,以使用Django RestFramework实现OAuth2 API

我已经实现了OAuth2 API,现在在创建user时遇到此错误。

我不确定是否与OAuth2 API有关,我认为是这样,因为错误表明:

Exception Type: MissingSchema at /authentication/register/
Exception Value: Invalid URL '127.0.0.1/o/token/': No schema supplied. Perhaps you meant http://127.0.0.1/o/token/?

URL /authentication/register/是在实现OAuth API时实现的。

  

使用以下命令创建用户时,出现错误,但是   即使出现此错误,也会在数据库中创建用户。

$ curl -d "username=halfsping&password=1234abcd" "http://127.0.0.1:8000/authentication/register/"

部分错误:

Exception Type: MissingSchema at /authentication/register/
Exception Value: Invalid URL '127.0.0.1/o/token/': No schema supplied. Perhaps you meant http://127.0.0.1/o/token/?

我是否使用它并不重要:

$ curl -d "username=halfsping&password=1234abcd" "http://127.0.0.1:8000/authentication/register/"

保护对象的urls.py:

from django.contrib import admin
from django.urls import path, include
from rest_framework import routers
from core.views import *
from unicorns.views import UnicornViewSet

router = routers.DefaultRouter()

router.register(r'customers', CustomerViewSet)
router.register(r'professions', ProfessionViewSet)
router.register(r'data-sheet', DataSheetViewSet)
router.register(r'document', DocumentViewSet)
router.register(r'unicorn', UnicornViewSet)

urlpatterns = [
    path('admin/', admin.site.urls),
    # Authentication
    path('o/', include('oauth2_provider.urls', namespace='oauth2_provider')),
    path('authentication/', include('users.urls')),
    # API
    path('api/', include(router.urls)),
    path('api-auth/', include('rest_framework.urls')),
]

完全错误:

Internal Server Error: /authentication/register/
Traceback (most recent call last):
  File "D:\virtual_envs\pet_api\lib\site-packages\django\core\handlers\exception.py", line 34, in inner
    response = get_response(request)
  File "D:\virtual_envs\pet_api\lib\site-packages\django\core\handlers\base.py", line 115, in _get_response
    response = self.process_exception_by_middleware(e, request)
  File "D:\virtual_envs\pet_api\lib\site-packages\django\core\handlers\base.py", line 113, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "D:\virtual_envs\pet_api\lib\site-packages\django\views\decorators\csrf.py", line 54, in wrapped_view
    return view_func(*args, **kwargs)
  File "D:\virtual_envs\pet_api\lib\site-packages\django\views\generic\base.py", line 71, in view
    return self.dispatch(request, *args, **kwargs)
  File "D:\virtual_envs\pet_api\lib\site-packages\rest_framework\views.py", line 495, in dispatch
    response = self.handle_exception(exc)
  File "D:\virtual_envs\pet_api\lib\site-packages\rest_framework\views.py", line 455, in handle_exception
    self.raise_uncaught_exception(exc)
  File "D:\virtual_envs\pet_api\lib\site-packages\rest_framework\views.py", line 492, in dispatch
    response = handler(request, *args, **kwargs)
  File "D:\virtual_envs\pet_api\lib\site-packages\rest_framework\decorators.py", line 55, in handler
    return func(*args, **kwargs)
  File "D:\web_proyects\pet_api\users\views.py", line 36, in register
    'client_secret': CLIENT_SECRET,
  File "D:\virtual_envs\pet_api\lib\site-packages\requests\api.py", line 116, in post
    return request('post', url, data=data, json=json, **kwargs)
  File "D:\virtual_envs\pet_api\lib\site-packages\requests\api.py", line 60, in request
    return session.request(method=method, url=url, **kwargs)
  File "D:\virtual_envs\pet_api\lib\site-packages\requests\sessions.py", line 519, in request
    prep = self.prepare_request(req)
  File "D:\virtual_envs\pet_api\lib\site-packages\requests\sessions.py", line 462, in prepare_request
    hooks=merge_hooks(request.hooks, self.hooks),
  File "D:\virtual_envs\pet_api\lib\site-packages\requests\models.py", line 313, in prepare
    self.prepare_url(url, params)
  File "D:\virtual_envs\pet_api\lib\site-packages\requests\models.py", line 387, in prepare_url
    raise MissingSchema(error)
requests.exceptions.MissingSchema: Invalid URL '127.0.0.1/o/token/': No schema supplied. Perhaps you meant http://127.0.0.1/o/token/?
[26/Jun/2019 09:54:49] "POST /authentication/register/ HTTP/1.1" 500 17932
D:\web_proyects\pet_api\users\views.py changed, reloading.
Watching for file changes with StatReloader
Performing system checks...

System check identified no issues (0 silenced).
June 26, 2019 - 09:56:39
Django version 2.2.1, using settings 'pet_api.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CTRL-BREAK.
D:\web_proyects\pet_api\users\views.py changed, reloading.
Watching for file changes with StatReloader
Performing system checks...

System check identified no issues (0 silenced).
June 26, 2019 - 09:58:30
Django version 2.2.1, using settings 'pet_api.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CTRL-BREAK.
[26/Jun/2019 09:58:35] "POST /authentication/register/ HTTP/1.1" 200 54
Method Not Allowed: /authentication/register/
[26/Jun/2019 09:58:50] "GET /authentication/register/ HTTP/1.1" 405 6074
Not Found: /
[26/Jun/2019 09:58:55] "GET / HTTP/1.1" 404 2352
[26/Jun/2019 09:59:00] "GET /api/ HTTP/1.1" 200 6174
Not Found: /
[26/Jun/2019 09:59:06] "GET / HTTP/1.1" 404 2352
Not Found: /api-auth/
[26/Jun/2019 09:59:14] "GET /api-auth/ HTTP/1.1" 404 2646
Not Found: /api-auth/api
[26/Jun/2019 09:59:20] "GET /api-auth/api HTTP/1.1" 404 2655
Not Found: /api-auth/api/
[26/Jun/2019 09:59:24] "GET /api-auth/api/ HTTP/1.1" 404 2658
Internal Server Error: /authentication/register/
Traceback (most recent call last):
  File "D:\virtual_envs\pet_api\lib\site-packages\django\core\handlers\exception.py", line 34, in inner
    response = get_response(request)
  File "D:\virtual_envs\pet_api\lib\site-packages\django\core\handlers\base.py", line 115, in _get_response
    response = self.process_exception_by_middleware(e, request)
  File "D:\virtual_envs\pet_api\lib\site-packages\django\core\handlers\base.py", line 113, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "D:\virtual_envs\pet_api\lib\site-packages\django\views\decorators\csrf.py", line 54, in wrapped_view
    return view_func(*args, **kwargs)
  File "D:\virtual_envs\pet_api\lib\site-packages\django\views\generic\base.py", line 71, in view
    return self.dispatch(request, *args, **kwargs)
  File "D:\virtual_envs\pet_api\lib\site-packages\rest_framework\views.py", line 495, in dispatch
    response = self.handle_exception(exc)
  File "D:\virtual_envs\pet_api\lib\site-packages\rest_framework\views.py", line 455, in handle_exception
    self.raise_uncaught_exception(exc)
  File "D:\virtual_envs\pet_api\lib\site-packages\rest_framework\views.py", line 492, in dispatch
    response = handler(request, *args, **kwargs)
  File "D:\virtual_envs\pet_api\lib\site-packages\rest_framework\decorators.py", line 55, in handler
    return func(*args, **kwargs)
  File "D:\web_proyects\pet_api\users\views.py", line 36, in register
    'client_secret': CLIENT_SECRET,
  File "D:\virtual_envs\pet_api\lib\site-packages\requests\api.py", line 116, in post
    return request('post', url, data=data, json=json, **kwargs)
  File "D:\virtual_envs\pet_api\lib\site-packages\requests\api.py", line 60, in request
    return session.request(method=method, url=url, **kwargs)
  File "D:\virtual_envs\pet_api\lib\site-packages\requests\sessions.py", line 519, in request
    prep = self.prepare_request(req)
  File "D:\virtual_envs\pet_api\lib\site-packages\requests\sessions.py", line 462, in prepare_request
    hooks=merge_hooks(request.hooks, self.hooks),
  File "D:\virtual_envs\pet_api\lib\site-packages\requests\models.py", line 313, in prepare
    self.prepare_url(url, params)
  File "D:\virtual_envs\pet_api\lib\site-packages\requests\models.py", line 387, in prepare_url
    raise MissingSchema(error)
requests.exceptions.MissingSchema: Invalid URL '127.0.0.1/o/token/': No schema supplied. Perhaps you meant http://127.0.0.1/o/token/?
[26/Jun/2019 10:00:43] "POST /authentication/register/ HTTP/1.1" 500 17933

0 个答案:

没有答案