0

I am newbie to Instagram Api. I am trying to figure out how to set proxy for InstagramApi using Python. Below is the basic code which I got from github. When I executed this code I got an error. I think I need to include proxy server.

How can I include a proxy server in this?

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)

I am getting below error:

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
halfer
  • 19,824
  • 17
  • 99
  • 186
Naveen Gabriel
  • 679
  • 2
  • 9
  • 25
  • The error indicates that the HTTP connection is refused, but I can't see that adding a proxy server is obviously the solution. Indeed if you are doing something to a remote server that its administrators do not like, in general they have the moral right to block you, and you should not try to circumvent this. – halfer Feb 05 '17 at 17:17

1 Answers1

0

It's not possible with the current version of python-instagram lib. But to deal with http requests, python-instagram uses httplib2 that allows you to set a Proxy Server : http://httplib2.readthedocs.io/en/latest/libhttplib2.html?highlight=proxyinfo#httplib2.ProxyInfo

You can fork the project, implement the feature and make a pull request.

Alternatively, you can try to use Instagram-API-python library. Proxy seems to be supported : https://github.com/LevPasha/Instagram-API-python/blob/master/InstagramAPI.py#L64

Thomas Lehoux
  • 1,158
  • 9
  • 13