【问题标题】:InstagramApi using Python: How to set up proxy server?InstagramApi 使用 Python:如何设置代理服务器?
【发布时间】:2017-02-01 15:26:43
【问题描述】:

我是 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

【问题讨论】:

  • 报错表示HTTP连接被拒绝,但是我看不出添加代理服务器显然是解决办法。事实上,如果您对远程服务器的管理员不喜欢做某事,通常他们有道德权利阻止您,您不应该试图规避这一点。

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


【解决方案1】:

当前版本的 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

【讨论】:

  • 我认为错误可能是由于其他原因。任何帮助将不胜感激。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-03-30
  • 2017-05-21
  • 1970-01-01
  • 1970-01-01
  • 2018-07-07
相关资源
最近更新 更多