欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

mac安装pycurl的坑

程序员文章站 2022-05-07 21:56:16
...

问题描述:
使用tornado时,要用proxy,一直不通,但是也没报错。

response = await AsyncHTTPClient().fetch(
          HTTPRequest(
                url="",
                validate_cert=False,
                proxy_host=PROXY_HOST,
                proxy_port=PROXY_PORT,
                proxy_username=PROXY_USERNAME,
                proxy_password=PROXY_PASSWORD
            )
        )

然后发现是AsyncHTTPClient这个东西要配成curl_httpclient才可以,不然默认的是simple_httpclient不能用proxy。(把我坑吐了)

官方文档里的:
proxy_host (str) – HTTP proxy hostname. To use proxies, proxy_host and proxy_port must be set; proxy_username, proxy_pass and proxy_auth_mode are optional. Proxies are currently only supported with curl_httpclient.

怎么配呢?

AsyncHTTPClient.configure("tornado.curl_httpclient.CurlAsyncHTTPClient")

然后跑起来之后这行代码又报错,给我整无语了????

    ImportError: pycurl: libcurl link-time ssl backends (secure-transport, openssl) do not include compile-time ssl backend (none/other)

看不懂,字面意思就是openssl没找到还是啥的,我就去重新装了下openssl,然后mac 装的好麻烦。。。气死个人

首先卸载当前的pycurl

pip uninstall pycurl
export PYCURL_SSL_LIBRARY=openssl
pip install pycurl --no-cache-dir    # 要加--no-cache-dir

如果不行的话,再设置几个变量
(后来发现下面的我好像没设成功????。。。主要是install的时候加上–no-cache-dir)

先找出你的ssh在哪
sudo find / -iname ssl.h
your-name:~$ export PYCURL_SSL_LIBRARY=openssl
your-name:~$ export LDFLAGS=-L安装目录/lib
your-name:~$ export CPPFLAGS=-I安装目录/include

参考:
https://www.jianshu.com/p/61fd0c16aef4
https://*.com/questions/21096436/ssl-backend-error-when-using-openssl

相关标签: python python