import requests
response = requests.get("https://www.example.com")
这失败,并显示错误:
Exception Value: Can't convert 'NoneType' object to str implicitly
还有其他方法可以在生产中启动django服务器吗?还是以其他方式在Python 2.x上运行https请求?
我尝试过httplib2
和urllib
。
尝试安装httplib
,但无法安装。
StackTrace:
None
[Wed Jul 11 17:39:24.537433 2018] [wsgi:error] [pid 22236:tid 139944512608000] Internal Server Error: /myproject/createUser/
[Wed Jul 11 17:39:24.537447 2018] [wsgi:error] [pid 22236:tid 139944512608000] Traceback (most recent call last):
[Wed Jul 11 17:39:24.537450 2018] [wsgi:error] [pid 22236:tid 139944512608000] File "/home/myproject/myprojectenv/lib/python3.5/site-packages/django/core/handlers/exception.py", line 35, in inner
[Wed Jul 11 17:39:24.537453 2018] [wsgi:error] [pid 22236:tid 139944512608000] response = get_response(request)
[Wed Jul 11 17:39:24.537455 2018] [wsgi:error] [pid 22236:tid 139944512608000] File "/home/myproject/myprojectenv/lib/python3.5/site-packages/django/core/handlers/base.py", line 128, in _get_response
[Wed Jul 11 17:39:24.537458 2018] [wsgi:error] [pid 22236:tid 139944512608000] response = self.process_exception_by_middleware(e, request)
[Wed Jul 11 17:39:24.537461 2018] [wsgi:error] [pid 22236:tid 139944512608000] File "/home/myproject/myprojectenv/lib/python3.5/site-packages/django/core/handlers/base.py", line 126, in _get_response
[Wed Jul 11 17:39:24.537464 2018] [wsgi:error] [pid 22236:tid 139944512608000] response = wrapped_callback(request, *callback_args, **callback_kwargs)
[Wed Jul 11 17:39:24.537467 2018] [wsgi:error] [pid 22236:tid 139944512608000] File "/home/myproject/myprojectenv/lib/python3.5/site-packages/django/views/decorators/csrf.py", line 54, in wrapped_view
[Wed Jul 11 17:39:24.537470 2018] [wsgi:error] [pid 22236:tid 139944512608000] return view_func(*args, **kwargs)
[Wed Jul 11 17:39:24.537472 2018] [wsgi:error] [pid 22236:tid 139944512608000] File "/home/myproject/myprojectenv/lib/python3.5/site-packages/django/views/generic/base.py", line 69, in view
[Wed Jul 11 17:39:24.537475 2018] [wsgi:error] [pid 22236:tid 139944512608000] return self.dispatch(request, *args, **kwargs)
[Wed Jul 11 17:39:24.537477 2018] [wsgi:error] [pid 22236:tid 139944512608000] File "/home/myproject/myprojectenv/lib/python3.5/site-packages/rest_framework/views.py", line 483, in dispatch
[Wed Jul 11 17:39:24.537480 2018] [wsgi:error] [pid 22236:tid 139944512608000] response = self.handle_exception(exc)
[Wed Jul 11 17:39:24.537483 2018] [wsgi:error] [pid 22236:tid 139944512608000] File "/home/myproject/myprojectenv/lib/python3.5/site-packages/rest_framework/views.py", line 443, in handle_exception
[Wed Jul 11 17:39:24.537485 2018] [wsgi:error] [pid 22236:tid 139944512608000] self.raise_uncaught_exception(exc)
[Wed Jul 11 17:39:24.537488 2018] [wsgi:error] [pid 22236:tid 139944512608000] File "/home/myproject/myprojectenv/lib/python3.5/site-packages/rest_framework/views.py", line 480, in dispatch
[Wed Jul 11 17:39:24.537491 2018] [wsgi:error] [pid 22236:tid 139944512608000] response = handler(request, *args, **kwargs)
[Wed Jul 11 17:39:24.537493 2018] [wsgi:error] [pid 22236:tid 139944512608000] File "/home/myproject/myapp/views.py", line 88, in get
[Wed Jul 11 17:39:24.537496 2018] [wsgi:error] [pid 22236:tid 139944512608000] aud,email = getEmailandAud(self,request)
[Wed Jul 11 17:39:24.537498 2018] [wsgi:error] [pid 22236:tid 139944512608000] File "/home/myproject/myapp/views.py", line 31, in getEmailandAud
[Wed Jul 11 17:39:24.537501 2018] [wsgi:error] [pid 22236:tid 139944512608000] response = requests.get("https://www.googleapis.com/oauth2/v1/tokeninfo?access_token=" + access_token)
[Wed Jul 11 17:39:24.537505 2018] [wsgi:error] [pid 22236:tid 139944512608000] TypeError: Can't convert 'NoneType' object to str implicitly
答案 0 :(得分:2)
问题中的代码不是应用程序代码中的代码。错误日志显示它具有:
response = requests.get("https://www.googleapis.com/oauth2/v1/tokeninfo?access_token=" + access_token)
此时的access_token
是None
,说明为什么会出错。如:
>>> access_token = None
>>> "https://www.googleapis.com/oauth2/v1/tokeninfo?access_token=" + access_token
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: cannot concatenate 'str' and 'NoneType' objects
如果您更改了代码以删除该代码,则说明您尚未重新启动服务器以获取新代码。
要了解有关重新启动代码更改的信息,请参阅: