Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

API.verify_credentials() throws Error instead of returning False if consumer_key is set to None #1489

Closed
Vendicated opened this issue Dec 30, 2020 · 1 comment
Labels
Improvement This is regarding an improvement to an existing feature
Milestone

Comments

@Vendicated
Copy link

Title says it all.

Example code:

import tweepy

auth = tweepy.OAuthHandler(None, None)

api = tweepy.API(auth)

api.verify_credentials()
Traceback
Traceback (most recent call last):
  File "/home/ven/.local/lib/python3.8/site-packages/tweepy/binder.py", line 184, in execute
    resp = self.session.request(self.method,
  File "/usr/lib/python3/dist-packages/requests/sessions.py", line 519, in request
    prep = self.prepare_request(req)
  File "/usr/lib/python3/dist-packages/requests/sessions.py", line 452, in prepare_request
    p.prepare(
  File "/usr/lib/python3/dist-packages/requests/models.py", line 317, in prepare
    self.prepare_auth(auth, url)
  File "/usr/lib/python3/dist-packages/requests/models.py", line 548, in prepare_auth
    r = auth(self)
  File "/home/ven/.local/lib/python3.8/site-packages/requests_oauthlib/oauth1_auth.py", line 108, in __call__
    r.url, headers, _ = self.client.sign(
  File "/usr/lib/python3/dist-packages/oauthlib/oauth1/rfc5849/__init__.py", line 313, in sign
    ('oauth_signature', self.get_oauth_signature(request)))
  File "/usr/lib/python3/dist-packages/oauthlib/oauth1/rfc5849/__init__.py", line 127, in get_oauth_signature
    uri, headers, body = self._render(request)
  File "/usr/lib/python3/dist-packages/oauthlib/oauth1/rfc5849/__init__.py", line 209, in _render
    headers = parameters.prepare_headers(
  File "/usr/lib/python3/dist-packages/oauthlib/oauth1/rfc5849/utils.py", line 32, in wrapper
    return target(params, *args, **kwargs)
  File "/usr/lib/python3/dist-packages/oauthlib/oauth1/rfc5849/parameters.py", line 59, in prepare_headers
    escaped_value = utils.escape(value)
  File "/usr/lib/python3/dist-packages/oauthlib/oauth1/rfc5849/utils.py", line 56, in escape
    raise ValueError('Only unicode objects are escapable. ' +
ValueError: Only unicode objects are escapable. Got None of type <class 'NoneType'>.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "test.py", line 7, in <module>
    api.verify_credentials()
  File "/home/ven/.local/lib/python3.8/site-packages/tweepy/api.py", line 662, in verify_credentials
    return bind_api(
  File "/home/ven/.local/lib/python3.8/site-packages/tweepy/binder.py", line 252, in _call
    return method.execute()
  File "/home/ven/.local/lib/python3.8/site-packages/tweepy/binder.py", line 192, in execute
    six.reraise(TweepError, TweepError('Failed to send request: %s' % e), sys.exc_info()[2])
  File "/usr/lib/python3/dist-packages/six.py", line 702, in reraise
    raise value.with_traceback(tb)
  File "/home/ven/.local/lib/python3.8/site-packages/tweepy/binder.py", line 184, in execute
    resp = self.session.request(self.method,
  File "/usr/lib/python3/dist-packages/requests/sessions.py", line 519, in request
    prep = self.prepare_request(req)
  File "/usr/lib/python3/dist-packages/requests/sessions.py", line 452, in prepare_request
    p.prepare(
  File "/usr/lib/python3/dist-packages/requests/models.py", line 317, in prepare
    self.prepare_auth(auth, url)
  File "/usr/lib/python3/dist-packages/requests/models.py", line 548, in prepare_auth
    r = auth(self)
  File "/home/ven/.local/lib/python3.8/site-packages/requests_oauthlib/oauth1_auth.py", line 108, in __call__`
    r.url, headers, _ = self.client.sign(
  File "/usr/lib/python3/dist-packages/oauthlib/oauth1/rfc5849/__init__.py", line 313, in sign
    ('oauth_signature', self.get_oauth_signature(request)))
  File "/usr/lib/python3/dist-packages/oauthlib/oauth1/rfc5849/__init__.py", line 127, in get_oauth_signature
    uri, headers, body = self._render(request)
  File "/usr/lib/python3/dist-packages/oauthlib/oauth1/rfc5849/__init__.py", line 209, in _render
    headers = parameters.prepare_headers(
  File "/usr/lib/python3/dist-packages/oauthlib/oauth1/rfc5849/utils.py", line 32, in wrapper
    return target(params, *args, **kwargs)
  File "/usr/lib/python3/dist-packages/oauthlib/oauth1/rfc5849/parameters.py", line 59, in prepare_headers
    escaped_value = utils.escape(value)
  File "/usr/lib/python3/dist-packages/oauthlib/oauth1/rfc5849/utils.py", line 56, in escape
    raise ValueError('Only unicode objects are escapable. ' +
tweepy.error.TweepError: Failed to send request: Only unicode objects are escapable. Got None of type <class 'NoneType'>.

Using:

  • Python 3.8.5
  • tweepy 3.10.0
@Harmon758
Copy link
Member

API.verify_credentials uses the Twitter API's GET account/verify_credentials endpoint.

The error originates from OAuthLib, which doesn't check the type of the consumer key or secret before attempting to use them to sign the API request.

The same error will be encountered when using any other API method to make a request to the Twitter API.

This isn't really a bug, since improper credentials are passed, but the error that occurs could probably be improved as it's a bit unclear.

@Harmon758 Harmon758 added the Improvement This is regarding an improvement to an existing feature label Dec 30, 2020
@Harmon758 Harmon758 added this to the 4.0 milestone Dec 30, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Improvement This is regarding an improvement to an existing feature
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants