0

I'm trying to use the python-twitter to eventually set up a twitter bot.

In IDLE, I've

import twitter

api = twitter.Api(consumer_key=['xxxx '],
                  consumer_secret=['xxx'],
                  access_token_key=['x-xxx'],
                  access_token_secret=['xx'])

then

api.VerifyCredentials()

which gives me a long traceback error as follows. What am I doing wrong?

Traceback (most recent call last):
  File "<pyshell#24>", line 1, in <module>
    api.VerifyCredentials()
  File "C:\Users\redye\AppData\Local\Programs\Python\Python39\lib\site-packages\twitter\api.py", line 4699, in VerifyCredentials
    resp = self._RequestUrl(url, 'GET', data)
  File "C:\Users\redye\AppData\Local\Programs\Python\Python39\lib\site-packages\twitter\api.py", line 4992, in _RequestUrl
    resp = self._session.get(url, auth=self.__auth, timeout=self._timeout, proxies=self.proxies)
  File "C:\Users\redye\AppData\Local\Programs\Python\Python39\lib\site-packages\requests\sessions.py", line 555, in get
    return self.request('GET', url, **kwargs)
  File "C:\Users\redye\AppData\Local\Programs\Python\Python39\lib\site-packages\requests\sessions.py", line 528, in request
    prep = self.prepare_request(req)
  File "C:\Users\redye\AppData\Local\Programs\Python\Python39\lib\site-packages\requests\sessions.py", line 456, in prepare_request
    p.prepare(
  File "C:\Users\redye\AppData\Local\Programs\Python\Python39\lib\site-packages\requests\models.py", line 320, in prepare
    self.prepare_auth(auth, url)
  File "C:\Users\redye\AppData\Local\Programs\Python\Python39\lib\site-packages\requests\models.py", line 551, in prepare_auth
    r = auth(self)
  File "C:\Users\redye\AppData\Local\Programs\Python\Python39\lib\site-packages\requests_oauthlib\oauth1_auth.py", line 108, in __call__
    r.url, headers, _ = self.client.sign(
  File "C:\Users\redye\AppData\Local\Programs\Python\Python39\lib\site-packages\oauthlib\oauth1\rfc5849\__init__.py", line 313, in sign
    ('oauth_signature', self.get_oauth_signature(request)))
  File "C:\Users\redye\AppData\Local\Programs\Python\Python39\lib\site-packages\oauthlib\oauth1\rfc5849\__init__.py", line 127, in get_oauth_signature
    uri, headers, body = self._render(request)
  File "C:\Users\redye\AppData\Local\Programs\Python\Python39\lib\site-packages\oauthlib\oauth1\rfc5849\__init__.py", line 209, in _render
    headers = parameters.prepare_headers(
  File "C:\Users\redye\AppData\Local\Programs\Python\Python39\lib\site-packages\oauthlib\oauth1\rfc5849\utils.py", line 32, in wrapper
    return target(params, *args, **kwargs)
  File "C:\Users\redye\AppData\Local\Programs\Python\Python39\lib\site-packages\oauthlib\oauth1\rfc5849\parameters.py", line 59, in prepare_headers
    escaped_value = utils.escape(value)
  File "C:\Users\redye\AppData\Local\Programs\Python\Python39\lib\site-packages\oauthlib\oauth1\rfc5849\utils.py", line 56, in escape
    raise ValueError('Only unicode objects are escapable. ' +
ValueError: Only unicode objects are escapable. Got <generator object to_unicode.<locals>.<genexpr> at 0x0000027FCEE7B510> of type <class 'generator'>.
booms
  • 23
  • 5
  • [This](https://stackoverflow.com/questions/25766051/python-oauthlib-in-escape-valueerror-only-unicode-objects-are-escapable) may answer your question – OctaveL Nov 25 '20 at 13:01
  • Hey, thanks for this - I eventually ended up trying it in VSCode and it worked perfectly. – booms Nov 25 '20 at 17:16
  • Unexpected, but nice! You should try explaining what fixed it more precisely before closing the thread to help others with the same issue in the future, if you have any idea what helped – OctaveL Nov 25 '20 at 17:25

1 Answers1

0

Thanks OctaveL for your help.

Eventually I found this video:

https://www.youtube.com/watch?v=ewq-91-e2fw

and followed it exactly. I was worried about exactly what the difference was in the API key and consumer key (there isn't any). Following the instructions in VSCode it all worked fine.

I suspect I messed up some formatting or spaces somewhere.

booms
  • 23
  • 5