Help with python urllib2 import error

In my script, I imported urrlib2, and the script worked fine. After rebooting, I get the following error:

  File "demo.py", line 2, in <module>
    import urllib2
  File "/usr/lib/python2.6/urllib2.py", line 92, in <module>
    import httplib
  File "/usr/lib/python2.6/httplib.py", line 78, in <module>
    import mimetools
  File "/usr/lib/python2.6/mimetools.py", line 6, in <module>
    import tempfile
  File "/usr/lib/python2.6/tempfile.py", line 34, in <module>
    from random import Random as _Random
ImportError: cannot import name Random

And when I do it import randomseparately, it works great. Any ideas what could be wrong?

I am using ubuntu 9.10 (updated). thank

+3
source share
2 answers

The usual answer: you have a file with a name random.pyin the current directory when you run the script. tempfilewill accidentally import this one random, not the stdlib module random.

+5
source

, random - stdlib, - sys.path.

>>> inspect.getabsfile(random)
0

Source: https://habr.com/ru/post/1726142/


All Articles