What happened to my computer? I always got a 'cookielib bug' even I changed my Python Version

StackOverflow https://stackoverflow.com/questions/20988268

  •  25-09-2022
  •  | 
  •  

Question

I want to learn the skill to log in websites with Python, so I copy other's code then try to understand them. I've write several web crawls which don't need to post data to the websites by myself. But this time, when I try to learn crawls that need post data, Python doesn't work.

It's the wrong message from Windows Command Line:

C:\Python26\lib\cookielib.py:1579: UserWarning: cookielib bug!
Traceback (most recent call last):
    File "C:\Python26\lib\cookielib.py", line 1577, in make_cookies
      parse_ns_headers(ns_hdrs), request)
    File "C:\Python26\lib\cookielib.py", line 1534, in _cookies_from_attrs_set
      cookie = self._cookie_from_cookie_tuple(tup, request)
    File "C:\Python26\lib\cookielib.py", line 1527, in _cookie_from_cookie_tuple
      rest)
    File "C:\Python26\lib\cookielib.py", line 764, in __init__
      self._rest = copy.copy(rest)
AttributeError: 'module' object has no attribute 'copy'

    _warn_unhandled_exception()

Actually, I have tried to use Python2.7.6 and Python2.6 and refresh 2.7.6 for times.

The code that I copied is from http://www.oschina.net/code/snippet_1253232_26503. This code is right because lots of people run this code .

I provide an account: Email='13018015260'(Also can be telephone number in this site),password='qwerty'

The code is not the problem, but the Python itself. Once I use cookielib in code, Python on my computer doesn't work!

Sorry for my poor English, I want to know the answer, because I even can't find similar problems in Google!

The screen picture

Était-ce utile?

La solution

Make sure that you do not have your own copy.py or copy.pyc in python path.

You can check that using following command in python interactive shell.

python -c "import copy; print(copy.__file__)"

It should print path something like:

c:\python27\lib\copy.pyc

If the above command print something that does not reference the file in standard library path, renamed the file (copy.py), and make sure you delete copy.pyc file.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top