Import requests library troubleshooting

Requests was installed via python3 -m pip install requests. Importing library was used to work well. But suddenly, it started to show me an error:

```
$ python3
Python 3.4.2 (v3.4.2:ab2c023a9432, Oct  5 2014, 20:42:22) 
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import requests
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/requests-2.5.3-py3.4.egg/requests/__init__.py", line 58, in <module>
    from . import utils
  File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/requests-2.5.3-py3.4.egg/requests/utils.py", line 12, in <module>
    import cgi
  File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/cgi.py", line 44, in <module>
    import tempfile
  File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/tempfile.py", line 34, in <module>
    import shutil as _shutil
  File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/shutil.py", line 14, in <module>
    import tarfile
  File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/tarfile.py", line 48, in <module>
    import copy
  File "/Users/artemdremov/Documents/grabber/copy.py", line 2, in <module>
    import urllib.request
  File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/urllib/request.py", line 102, in <module>
    from urllib.error import URLError, HTTPError, ContentTooShortError
  File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/urllib/error.py", line 14, in <module>
    import urllib.response
  File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/urllib/response.py", line 14, in <module>
    class addbase(tempfile._TemporaryFileWrapper):
AttributeError: 'module' object has no attribute '_TemporaryFileWrapper'
```

I work under OS X 10.10.


That traceback seems to pass through some of your own code, specifically a module called `copy`. Is that new?


To be clear, @Lukasa is talking about 

```
  File "/Users/artemdremov/Documents/grabber/copy.py", line 2, in <module>
```

I'm rather surprised though that that would even be used. I thought that absolute imports on Python 3 would be preferring the stdlib's copy module.


@Lukasa Yes, this was a second python script, that used request module. Importing request library worked well in first file.


What I'm concerned about is that this new module leads to urllib being on the import path, which is also where the error is coming from. Indeed, this looks like a circular import, as your import of requests causes an import of tempfile, which ends up importing urllib which then imports tempfile again.


Specifically the import of tempfile never completes, so when urllib tries to import it, we go back through that look. @theasder can you try importing requests on its own from a different directory or renaming `grabber/copy.py` to `grabber/_copy.py`?


After renaming grabber/copy.py to grabber/_copy.py

```
$ python3
Python 3.4.2 (v3.4.2:ab2c023a9432, Oct  5 2014, 20:42:22) 
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import requests
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/requests-2.5.3-py3.4.egg/requests/__init__.py", line 58, in <module>
    from . import utils
  File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/requests-2.5.3-py3.4.egg/requests/utils.py", line 12, in <module>
    import cgi
  File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/cgi.py", line 44, in <module>
    import tempfile
  File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/tempfile.py", line 34, in <module>
    import shutil as _shutil
  File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/shutil.py", line 14, in <module>
    import tarfile
  File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/tarfile.py", line 48, in <module>
    import copy
ImportError: bad magic number in 'copy': b'\x03\xf3\r\n'
```


You'll also need to remove the `__pycache__` directory or at least `__pycache__/copy.pyc`.


@sigmavirus24 hooray, it works, thank you!


Excellent! Thanks for the report @theasder.