InstagramApi使用Python:如何设置代理服务器?

时间:2017-02-01 15:26:44

标签: python api sockets instagram-api connection-refused

我是Instagram Api的新手。我试图弄清楚如何使用Python设置InstagramApi的代理。下面是我从github获得的基本代码。当我执行此代码时,我收到了一个错误。我想我需要包含代理服务器。

如何在此包含代理服务器?

from instagram.client import InstagramAPI

access_token="*******************************"
client_secret="******************************"

api = InstagramAPI(access_token=access_token, client_secret=client_secret)
recent_media, next_ = api.user_recent_media(user_id="jey07", count=4)
for media in recent_media:
   print(media.caption.text)

我收到以下错误:

File "C:\Users\Gabriel\AppData\Local\Programs\Python\Python36\lib\socket.py", line 713, in create_connection
sock.connect(sa)
ConnectionRefusedError: [WinError 10061] No connection could be made because the target machine actively refused it

1 个答案:

答案 0 :(得分:0)

当前版本的python-instagram lib无法实现。但是为了处理http请求,python-instagram使用了允许你设置代理服务器的httplib2:http://httplib2.readthedocs.io/en/latest/libhttplib2.html?highlight=proxyinfo#httplib2.ProxyInfo

您可以分叉项目,实现该功能并发出拉取请求。

或者,您可以尝试使用 Instagram-API-python 库。似乎支持代理:https://github.com/LevPasha/Instagram-API-python/blob/master/InstagramAPI.py#L64