9

I'm using python-social-auth to login with social networks from my Django application. On my local machine everything works fine, but when I deploy to a server I get the following error:

oauthlib.oauth1.rfc5849.utils in escape
ValueError: Only unicode objects are escapable. Got None of type <type 'NoneType'>.

Stacktrace:

File "django/core/handlers/base.py", line 112, in get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "social/apps/django_app/utils.py", line 45, in wrapper
    return func(request, backend, *args, **kwargs)
File "social/apps/django_app/views.py", line 12, in auth
    return do_auth(request.social_strategy, redirect_name=REDIRECT_FIELD_NAME)
File "social/actions.py", line 25, in do_auth
    return strategy.start()
File "social/strategies/base.py", line 66, in start
    return self.redirect(self.backend.auth_url())
File "social/backends/oauth.py", line 99, in auth_url
    token = self.set_unauthorized_token()
File "social/backends/oauth.py", line 158, in set_unauthorized_token
    token = self.unauthorized_token()
File "social/backends/oauth.py", line 177, in unauthorized_token
    method=self.REQUEST_TOKEN_METHOD)
File "social/backends/base.py", line 202, in request
    response = request(method, url, *args, **kwargs)
File "requests/api.py", line 44, in request
    return session.request(method=method, url=url, **kwargs)
File "requests/sessions.py", line 349, in request
    prep = self.prepare_request(req)
File "requests/sessions.py", line 287, in prepare_request
    hooks=merge_hooks(request.hooks, self.hooks),
File "requests/models.py", line 291, in prepare
    self.prepare_auth(auth, url)
File "requests/models.py", line 470, in prepare_auth
    r = auth(self)
File "requests_oauthlib/oauth1_auth.py", line 87, in __call__
    unicode(r.url), unicode(r.method), None, r.headers)
File "oauthlib/oauth1/rfc5849/__init__.py", line 293, in sign
    request.oauth_params.append(('oauth_signature', self.get_oauth_signature(request)))
File "oauthlib/oauth1/rfc5849/__init__.py", line 128, in get_oauth_signature
    uri, headers, body = self._render(request)
File "oauthlib/oauth1/rfc5849/__init__.py", line 199, in _render
    headers = parameters.prepare_headers(request.oauth_params, request.headers, realm=realm)
File "oauthlib/oauth1/rfc5849/utils.py", line 31, in wrapper
    return target(params, *args, **kwargs)
File "oauthlib/oauth1/rfc5849/parameters.py", line 57, in prepare_headers
    escaped_value = utils.escape(value)
File "oauthlib/oauth1/rfc5849/utilsy", line 56, in escape
    'Got %s of type %s.' % (u, type(u)))

Some packages from requirements.txt file:

Django==1.6.6
google-api-python-client==1.1
oauth2==1.5.211
oauthlib==0.6.3
python-openid==2.2.5
python-social-auth==0.1.26
requests==2.4.0
requests-oauthlib==0.4.1
six==1.7.3
cansadadeserfeliz
  • 3,033
  • 5
  • 34
  • 50
  • What version of Python are you using? I have a suspicion about what's causing this, but I'm not 100% certain. – Ian Stapleton Cordasco Sep 11 '14 at 12:14
  • @sigmavirus24 It's Python 2.7.6. In the same machine I have another Django project that uses ``python-social-auth`` and it works absolutely fine. – cansadadeserfeliz Sep 11 '14 at 12:33
  • I thought the difference might be in the `locale` settings but given you have a different app using it that is very curious. I'm not familiar with these projects to be helpful, but I'll point the maintainers of requests-oauthlib at this to see if they can help. – Ian Stapleton Cordasco Sep 11 '14 at 14:12
  • @sigmavirus24 Thank you for helping! I checked ``locale``and it's ``en_US.UTF-8``. Since both Django projects are running in the same server, they share the same ``locale``, but one project works well, and the other one not. – cansadadeserfeliz Sep 11 '14 at 14:26
  • Same problem, trying to upgrade t Django 1.7. Google suggests something is wrong with the variable name in the settings-file but of course, what the *correct* variable name is is of course not shown anywhere. – kaleissin Sep 20 '14 at 19:26

3 Answers3

3

I got this error when I did not provide my OAuth Consumer key and secrets in my django settings file. It's essentially a "Required setting not found" error. Is it worth checking all your settings copied across successfully when you deployed?

Steve Bradshaw
  • 827
  • 7
  • 10
0

I've upgraded to python-social-auth and had the same problem with Linkedin login. Parameter names in settings are changed in the latest version so instead: LINKEDIN_CONSUMER_KEY and LINKEDIN_CONSUMER_SECRET it'd be used: SOCIAL_AUTH_LINKEDIN_KEY and SOCIAL_AUTH_LINKEDIN_SECRET.

user626710
  • 556
  • 5
  • 4
-2

the problem comes to you if this statement have spelling mistake:

tweepy.OAuthHandler(consumer_key,consumer_secret)
Rabbid76
  • 202,892
  • 27
  • 131
  • 174