python - request.get("https://www.example.com") 在尝试使用 Apache 和 mod_wsgi 运行 Django 应用程序时不起作用
python - request.get("https://www.example.com") doesn't work when trying to run Django app with Apache and mod_wsgi
import requests
response = requests.get("https://www.example.com")
失败并出现错误:
Exception Value: Can't convert 'NoneType' object to str implicitly
尝试了提到的所有步骤here and here,但没有成功。
有没有其他方法可以在生产环境中启动 django 服务器?或 运行 Python 2.x?
上的 https 请求的任何其他方式
我试过httplib2
和urllib
。
尝试安装 httplib
但无法安装。
堆栈跟踪:
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
问题中的代码不是您的应用程序代码中的代码。错误日志显示它有:
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
如果您更改了代码以删除它,则您还没有重新启动服务器以获取新代码。
要了解如何重新启动代码更改,请参阅:
import requests
response = requests.get("https://www.example.com")
失败并出现错误:
Exception Value: Can't convert 'NoneType' object to str implicitly
尝试了提到的所有步骤here and here,但没有成功。
有没有其他方法可以在生产环境中启动 django 服务器?或 运行 Python 2.x?
上的 https 请求的任何其他方式我试过httplib2
和urllib
。
尝试安装 httplib
但无法安装。
堆栈跟踪:
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
问题中的代码不是您的应用程序代码中的代码。错误日志显示它有:
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
如果您更改了代码以删除它,则您还没有重新启动服务器以获取新代码。
要了解如何重新启动代码更改,请参阅: