14

I have a Python script with just these 2 lines:

import requests
print len(dir(requests))

It prints:

12
48

When I print the actual list dir(requests), I get this:

['__author__', '__build__', '__builtins__', '__copyright__', '__doc__', '__file__', '__license__', '__name__', '__package__', '__path__', '__title__', '__version__']
['ConnectionError', 'HTTPError', 'NullHandler', 'PreparedRequest', 'Request', 'RequestException', 'Response', 'Session', 'Timeout', 'TooManyRedirects', 'URLRequired', '__author__', '__build__', '__builtins__', '__copyright__', '__doc__', '__file__', '__license__', '__name__', '__package__', '__path__', '__title__', '__version__', 'adapters', 'api', 'auth', 'certs', 'codes', 'compat', 'cookies', 'delete', 'exceptions', 'get', 'head', 'hooks', 'logging', 'models', 'options', 'packages', 'patch', 'post', 'put', 'request', 'session', 'sessions', 'status_codes', 'structures', 'utils']

I'm guessing there are multiple requests modules or something like that. Please help.

Bruce
  • 945
  • 3
  • 12
  • 24

2 Answers2

17

You gave your script a name of a standard module or something else that is imported by the requests package. You created a circular import.

yourscript -> import requests -> [0 or more other modules] -> import yourscript -> import requests again

Because requests didn't complete importing the first time you get to see these differences in the list of supported objects.

Don't do that. Rename your script to something else and it'll all work.

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
1

First one is your own module Second is module for dealing with HTTP requests. Rename ur own module