简体   繁体   中英

Trouble using the requests package python 3.2

I'm trying to get a basic web scraping script running just to test some things out and I noticed a lot of people recommending the "requests" package so I downloaded it but I am getting some weird responses and I'm hoping someone could help me interpret them as I am very new to python

import requests
r = requests.get('http://www.python.org')
r.content

and the output is this:

C:\Python32\python.exe "D:/Code Testing/Missing Time/webscraper.py"
Traceback (most recent call last):
  File "D:/Code Testing/Missing Time/webscraper.py", line 1, in <module>
    import requests
  File "C:\Python32\lib\site-packages\requests-2.11.1-py3.2.egg\requests\__init__.py", line 52, in <module>
    from .packages.urllib3.contrib import pyopenssl
  File "C:\Python32\lib\site-packages\requests-2.11.1-py3.2.egg\requests\packages\__init__.py", line 39, in <module>
    from . import idna
  File "C:\Python32\lib\site-packages\requests-2.11.1-py3.2.egg\requests\packages\idna\__init__.py", line 1, in <module>
    from .core import *
  File "C:\Python32\lib\site-packages\requests-2.11.1-py3.2.egg\requests\packages\idna\core.py", line 10
_unicode_dots_re = re.compile(u'[\u002e\u3002\uff0e\uff61]')
                                                          ^
SyntaxError: invalid syntax

The requests module, version 2.11.1, doesn't support Python 3.2 - see the end of their PyPI page . You have a few options:

  • Best, if you control your desktop, is to install a newer version of Python.
  • If you can't do that, and don't have the wherewithal to get a newer version of python installed for you, you could try using an older version of requests. Going off the tags on PyPI, 1.0.0 claims to supported Python 3.2 but the 2.0.0 version doesn't.
  • Use a different library. This would be unfortunate, as requests really is an excellent HTTP library.

There are some very real downsides to running old versions of libraries, namely missing features and the possibility of security vunerabilities . This is not a theoretical possibility - see this CVE for example. For more details, see requests vulnerability disclosure page .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM