scrapy是python網頁抓取框架, 是編寫爬蟲的利器,但是新手在安裝的時候經常會遇到各種問題, 今天我們就來看一個openssl版本引起的問題,遇到這個問題,我們需要的是給openssl打補丁。
[python@pythontab dev]$ sudo pip install scrapy … OpenSSL/ssl/connection.c: In function ‘ssl_Connection_set_context’: OpenSSL/ssl/connection.c:289: warning: implicit declaration of function ‘SSL_set_SSL_CTX’ OpenSSL/ssl/connection.c: In function ‘ssl_Connection_get_servername’: OpenSSL/ssl/connection.c:313: error: ‘TLSEXT_NAMETYPE_host_name’ undeclared (first use in this function) OpenSSL/ssl/connection.c:313: error: (Each undeclared identifier is reported only once OpenSSL/ssl/connection.c:313: error: for each function it appears in.) OpenSSL/ssl/connection.c:320: warning: implicit declaration of function ‘SSL_get_servername’ OpenSSL/ssl/connection.c:320: warning: assignment makes pointer from integer without a cast OpenSSL/ssl/connection.c: In function ‘ssl_Connection_set_tlsext_host_name’: OpenSSL/ssl/connection.c:346: warning: implicit declaration of function ‘SSL_set_tlsext_host_name’ error: command ‘gcc’ failed with exit status 1
報錯了。
透過分析上面的錯誤可以看出是ssl的問題,原來是pyopenssl 0.13的版本和openssl不相容,需要打補丁。
下面說一下給pyOpenSSL打補丁的方法:
[python@pythontab dev]$ wget https://bugs.launchpad.net/pyopenssl/+bug/845445/+attachment/2666639/+files/pyOpenSSL-0.13.centos5.patch thanks to Philip K. Warren (pkwarren) [python@pythontab dev]$ wget http://pypi.python.org/packages/source/p/pyOpenSSL/pyOpenSSL-0.13.tar.gz [python@pythontab dev]$ grep “#define OPENSSL_VERSION_TEXT” /usr/include/openssl/opensslv.h #define OPENSSL_VERSION_TEXT “OpenSSL 0.9.8e-fips-rhel5 01 Jul 2008″ #define OPENSSL_VERSION_TEXT “OpenSSL 0.9.8e-rhel5 01 Jul 2008″ [python@pythontab dev]$ mv *.patch pyOpenSSL-0.13 [python@pythontab dev]$ cd pyOpenSSL-0.13 [python@pythontab pyOpenSSL-0.13]$ patch -p1 < pyOpenSSL-0 centospatchbr style='font-size:13px;font-style:normal;font-weight:normal;color:rgb(51, 51, 51);' />patching file OpenSSL/ssl/connection.c patching file OpenSSL/ssl/context.c [python@pythontab pyOpenSSL-0.13]$ sudo python setup.py install [python@pythontab dev]$ sudo pip install –upgrade scrapy
好了,現在scrapy安裝成功。
如果還有不明白的地方,歡迎留言提問!