Scientific Computing with Python: Using Twitter APIs

I’m working through the Scientific Computing with Python course and trying to get example code (video linked below) working with a Twitter API.

Here’s my repl:

All of this code is taken from the video and from related resources at

I managed to get the previous example (Google Maps API) to work, using an API key (i.e. the code I commented out in When I try to access the Twitter API though, I get a 403 (Forbidden) error. I believe this means that my request is properly formed but just denied for some reason?

I have no experience of working with APIs like this and only a rudimentary knowledge of Python, so this is pretty advanced stuff in the context of a beginner Python course. I could put a pin in it and move on, but if anyone can shed any light on this, I’d be most grateful, thanks.

Do you have real Twitter authorization tokens (API Key) to work with?

Yes, and they’re stored in environment variables. The 403 (forbidden) error suggests to me that my request is valid and signed but just denied for some reason, though I don’t really have much idea what I’m doing to be fair.

If you change the token to something invalid, do you get a different error? Just to test it

Yes, I get a 401 (Unauthorised) error.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.