Django-facebook icon indicating copy to clipboard operation
Django-facebook copied to clipboard

the JSON object must be str, not 'bytes'

Open procmail opened this issue 10 years ago • 10 comments

When trying to log in with Facebook on /facebook/example/ , this is what I get:

TypeError at /facebook/connect/ the JSON object must be str, not 'bytes' Request Method: POST Request URL: http://www.example.com/facebook/connect/ Django Version: 1.7 Exception Type: TypeError Exception Value:
the JSON object must be str, not 'bytes' Exception Location: /usr/local/lib/python3.4/json/init.py in loads, line 312 Python Executable: /usr/home/eric/virtualenvs/djangovirt/bin/python Python Version: 3.4.1 Python Path:
['/usr/home/eric/virtualenvs/djangovirt/djangoproj', '/usr/local/lib/python34.zip', '/usr/local/lib/python3.4', '/usr/local/lib/python3.4/plat-freebsd10', '/usr/local/lib/python3.4/lib-dynload', '/usr/home/eric/virtualenvs/djangovirt/lib/python3.4/site-packages', '/usr/home/eric/virtualenvs/djangovirt'] Server time: Wed, 15 Oct 2014 16:09:34 +0800

procmail avatar Oct 15 '14 08:10 procmail

I didn't test with Django 1.7 and python 3.4 just yet. A pull request would be much appreciated.

tschellenbach avatar Oct 15 '14 08:10 tschellenbach

I am having the same problem when using FacebookAuthorization.parse_signed_data(). I narrowed it down to the decoded payload, on line 475 in api.py, not being decoded to string.

stianpr avatar Oct 16 '14 13:10 stianpr

Really loving this package @tschellenbach! Unfortunately I'm using Python 3.4 with Django 1.7 as well - would you have an idea when you'll be able to make a fix for this? Unfortunately I'm not a good enough programmer to fix it myself, but are willing to wait to build this feature until it is stable for my setup. Hope to see an update soon :)

jonasspott avatar Oct 19 '14 09:10 jonasspott

I'm working on a fix here: 7d1219b36ef9318495032d8dd0626d11b45fbf9a . Though not finalised yet so do not use it. It would be very nice if people would test this fix =) I'm working on the tests now and I will release potential fixes for those ASAP.

stianpr avatar Oct 21 '14 13:10 stianpr

Great guys, much appreciated!

tschellenbach avatar Oct 21 '14 13:10 tschellenbach

@tschellenbach I'm having a hard time to test this change. How can I run all tests locally and those specifically for open_facebook?

I want to make sure this fix doesn't break anything in python 2, because all tests with python 2 should pass right? An official python 3 release is not out there yet, if I'm correct , so this is just a bonus for those using django-facebook in python 3 environment IMO.

stianpr avatar Oct 21 '14 13:10 stianpr

the current version is python 3 compatible in terms of test coverage. but not everything is tested

tschellenbach avatar Oct 21 '14 14:10 tschellenbach

have a look at how the travis.yml file runs the tests

tschellenbach avatar Oct 21 '14 14:10 tschellenbach

The snippet [https://github.com/tschellenbach/Django-facebook/commit/7d1219b36ef9318495032d8dd0626d11b45fbf9a] looks to work for me. I'm running python 3.4.3

pterofractal avatar Mar 15 '15 11:03 pterofractal

I have the same problem... i'm using django 1.8.5 and python 3.4.2, but when i go to /facebook/connect/ my project crash... this is my traceback:

Traceback: File "/home/axelio/public_html/virtualenvs/project/lib/python3.4/site-packages/django/core/handlers/base.py" in get_response 132. response = wrapped_callback(request, _callback_args, *_callback_kwargs) File "/home/axelio/public_html/virtualenvs/project/lib/python3.4/site-packages/django/views/decorators/csrf.py" in wrapped_view 58. return view_func(_args, *_kwargs) File "/home/axelio/public_html/virtualenvs/project/lib/python3.4/site-packages/django_facebook/decorators.py" in wrapped_view 99. response = self.authenticate(self.fn, request, _args, *_kwargs) File "/home/axelio/public_html/virtualenvs/project/lib/python3.4/site-packages/django_facebook/decorators.py" in authenticate 175. request, redirect_uri=redirect_uri) File "/home/axelio/public_html/virtualenvs/project/lib/python3.4/site-packages/django_facebook/api.py" in require_persistent_graph 28. graph = get_persistent_graph(request, _args, *_kwargs) File "/home/axelio/public_html/virtualenvs/project/lib/python3.4/site-packages/django_facebook/api.py" in get_persistent_graph 83. graph = get_facebook_graph(request, _args, *_kwargs) File "/home/axelio/public_html/virtualenvs/project/lib/python3.4/site-packages/django_facebook/api.py" in get_facebook_graph 155. signed_data = parse_signed_request(signed_request_string) File "/home/axelio/public_html/virtualenvs/project/lib/python3.4/site-packages/django_facebook/utils.py" in parse_signed_request 164. signed_request_string) File "/home/axelio/public_html/virtualenvs/project/lib/python3.4/site-packages/open_facebook/api.py" in parse_signed_data 475. data = json.loads(base64_url_decode_php_style(payload)) File "/usr/lib/python3.4/json/init.py" in loads 312. s.class.name))

Exception Type: TypeError at /facebook/connect/ Exception Value: the JSON object must be str, not 'bytes'

axeliodiaz avatar Nov 26 '15 01:11 axeliodiaz