Issue
import requests
response = requests.get("https://www.example.com")
This fails with error:
Exception Value: Can't convert 'NoneType' object to str implicitly
Tried all the steps mentioned here and here without any success.
Is there any other way to start django server in production? Or any other way to run https requests on Python 2.x?
I have tried httplib2
and urllib
.
Tried installing httplib
but couldn't install.
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
Solution
The code you have in the question, is not what is in your application code. The error logs shows it has:
response = requests.get("https://www.googleapis.com/oauth2/v1/tokeninfo?access_token=" + access_token)
The access_token
at that point is None
and why you get the error. As in:
>>> 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
If you changed the code to remove that, you have not restarted the server to have the new code picked up.
To learn about restarting on code changes see:
Answered By - Graham Dumpleton
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.