Skip to content

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

Description

@Vendicated

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    ImprovementThis is regarding an improvement to an existing feature

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions