Python-request.get(“https:/www.example.com”)在试图使用Apache和mod_wSGi运行Django应用程序时不起作用

内容来源于 Stack Overflow,并遵循CC BY-SA 3.0许可协议进行翻译与使用

  • 回答 (1)
  • 关注 (0)
  • 查看 (117)
import requests

response = requests.get("https://www.example.com")

这失败了,错误:

Exception Value: Can't convert 'NoneType' object to str implicitly

生产中是否还有其他方式可以使用Djangojango服务器?或者在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

如果你更改了代码以删除它,则表示尚未重新启动服务器以获取新代码。

扫码关注云+社区

领取腾讯云代金券