OAuth working on one machine, but not on the other


Hi there,

I am using the Tweepy library with Python3 to authenticate with the Twitter API. While the same code works on my Mac, it fails on my Linux machine.

I have already checked the time of the lInux machine, but looks OK, so the timestamp should not be an issue, I guess.

Here are the requests and the results:

On my Mac (OK):

send: b'GET /1.1/account/verify_credentials.json HTTP/1.1\r\nAccept-Encoding: identity\r\nHost: api.twitter.com\r\nAuthorization: OAuth oauth_nonce="61595438212939842091549201358", oauth_timestamp="1549201358", oauth_version="1.0", oauth_signature_method="HMAC-SHA1", oauth_consumer_key="<key>", oauth_token="<token>", oauth_signature="dFc2fpCmLYAP9F2mgomSADqZRgo%3D"\r\n\r\n'
reply: 'HTTP/1.1 200 OK\r\n'

On my Linux machine (NOK)

send: b'GET /1.1/account/verify_credentials.json HTTP/1.1\r\nAccept-Encoding: identity\r\nAuthorization: OAuth oauth_nonce="4698684625769646481549201366", oauth_timestamp="1549201366", oauth_version="1.0", oauth_signature_method="HMAC-SHA1", oauth_consumer_key="<key>", oauth_token="<token>", oauth_signature="c%2F.8xhsKiNfYHM9Y9cU4ZnIzL6mM%3D."\r\nHost: api.twitter.com\r\n\r\n'
reply: 'HTTP/1.1 401 Authorization Required\r\n'

I am using the same keys and tokens for both machines. But for some reason the request on the Linux machine fails.

Any ideas?


Just a wild guess…system clocks out-of-sync?


I have checked that already, the clock is OK. Currently I assume it must be related to how Tweepy is encrypting the request, I guess.


Just a guess too - are SSL certs up to date on the machine? in ubuntu it’s ca-certificates package


I’d like to investigate that. But I am not using Ubuntu. My machine is a QNAP NAS. I believe they are running their own Linux distribution.

Which SSL certificates are you talking about? I might try to find out what is the equivalent on my machine.


A while ago i had a similar error - SSL certs used by Python (or Java) can sometimes not match what’s on the system, so trying things in curl works, but would fail in a script - or vice versa, script calls would work but curl would fail.

Try updating certifi on the off chance that this is the case:

pip install --upgrade certifi


Thank you all. I could solve the issue, but I cannot tell for sure, how. It could have been the certificates as mentioned (although certifi was up to date)

Here is what I did:
On my QNAP NAS I had installed Python 3.5 through the WebAdmin interface before. At that time, no command line package manager was available.
In order to resolve my original problem, I wanted to install requests[security], because I thought this might fix the issue. However, the installation via pip failed, because package cffi could not be compiled (“no compiler found”). So I wanted to install gcc.
In order to do that I needed a package manager. I found entware-ng for my NAS, installed this, and after that GCC - but no luck. cffi would still not compile.
But I saw that the package manager offered a newer version of Python (3.6 - I had 3.5). Installed that and - BANG - it worked.
I assume that my Python 3.5 installation through the WebAdmin interface was sort of incomplete, outdated, whatever.

Thank you all for your hints!