Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

help with python urllib2 import error

In my script, I've imported urrlib2 and the script was working fine. After reboot, 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 import random separately, it works fine. Any ideas what might be wrong?

I'm using ubuntu 9.10 (up to date). thanks


1 Answers

The usual answer is that you've got a file called random.py in the current directory when the script is running. tempfile would be accidentally importing that random and not the stdlib random module.

like image 113
bobince Avatar answered Jul 14 '26 16:07

bobince



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!