jarrodnorwell / InstaPy2

Instagram automation tool for farming comments, follows and likes, written in Python
GNU General Public License v3.0
52 stars 9 forks source link

How to use proxies ? #19

Closed Senooy closed 1 year ago

Senooy commented 1 year ago

Hi,

I'm reading the source code and I saw that we can use proxies but It doesn't seems to work like InstaPy.

Any recommendations ? I'm using private proxies with usernames and passwords

jarrodnorwell commented 1 year ago

Reading the instagrapi documentation it looks like I've messed up the proxy implementation, I'll change this later and make a pr.

Basically, you'll make a dictionary with the required info or a full string for the proxy(ies).

Senooy commented 1 year ago

Nice, thanks a lot, I'm putting an alert on the repo. Could we have an example of a session using proxies once it's done ?

Thanks ! 😄

jarrodnorwell commented 1 year ago

I've been adding stuff to the GitBook so I'll make sure to once the proxies are fixed.

jarrodnorwell commented 1 year ago

@Senooy fixed proxies, will make a write-up soon but basically session.set_proxies(proxies=['http|https://user:pass@host:port', '...'])

jarrodnorwell commented 1 year ago

@Senooy Just deleted the comment, it contained your username and password.

Could you remove them and share it again?

Senooy commented 1 year ago

Thanks, I forgot about that, here we go :

root@crm-falcon:~/InstaPy2# python falconmarketing.py [INFO]: Created session using proxy: http|https://username:password@185.199.229.156:7492. Traceback (most recent call last): File "/usr/lib/python3/dist-packages/urllib3/connection.py", line 159, in _new_conn conn = connection.create_connection( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/lib/python3/dist-packages/urllib3/util/connection.py", line 61, in create_connection for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/lib/python3.11/socket.py", line 962, in getaddrinfo for res in _socket.getaddrinfo(host, port, family, type, proto, flags): ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ socket.gaierror: [Errno -2] Name or service not known

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 662, in urlopen self._prepare_proxy(conn) File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 950, in _prepare_proxy conn.connect() File "/usr/lib/python3/dist-packages/urllib3/connection.py", line 314, in connect conn = self._new_conn() ^^^^^^^^^^^^^^^^ File "/usr/lib/python3/dist-packages/urllib3/connection.py", line 171, in _new_conn raise NewConnectionError( urllib3.exceptions.NewConnectionError: <urllib3.connection.VerifiedHTTPSConnection object at 0x7f5c85310210>: Failed to establish a new connection: [Errno -2] Name or service not known

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/usr/local/lib/python3.11/dist-packages/requests/adapters.py", line 489, in send resp = conn.urlopen( ^^^^^^^^^^^^^ File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 719, in urlopen retries = retries.increment( ^^^^^^^^^^^^^^^^^^ File "/usr/lib/python3/dist-packages/urllib3/util/retry.py", line 436, in increment raise MaxRetryError(_pool, url, error or ResponseError(cause)) urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='i.instagram.com', port=443): Max retries exceeded with url: /api/v1/accounts/contact_point_prefill/ (Caused by ProxyError('Cannot connect to proxy.', NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x7f5c85310210>: Failed to establish a new connection: [Errno -2] Name or service not known')))

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/usr/local/lib/python3.11/dist-packages/instagrapi/mixins/private.py", line 288, in _send_private_request response = self.private.post( ^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/dist-packages/requests/sessions.py", line 635, in post return self.request("POST", url, data=data, json=json, kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/dist-packages/requests/sessions.py", line 587, in request resp = self.send(prep, send_kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/dist-packages/requests/sessions.py", line 701, in send r = adapter.send(request, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/dist-packages/requests/adapters.py", line 559, in send raise ProxyError(e, request=request) requests.exceptions.ProxyError: HTTPSConnectionPool(host='i.instagram.com', port=443): Max retries exceeded with url: /api/v1/accounts/contact_point_prefill/ (Caused by ProxyError('Cannot connect to proxy.', NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x7f5c85310210>: Failed to establish a new connection: [Errno -2] Name or service not known')))

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/root/InstaPy2/falconmarketing.py", line 33, in session.login(username='falconmarketingfr', password='XXXX') File "/usr/local/lib/python3.11/dist-packages/instapy2/instapy2_base.py", line 27, in login logged_in = self.session.login(username=username, password=password, verification_code=verification_code) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/dist-packages/instagrapi/mixins/auth.py", line 371, in login self.pre_login_flow() File "/usr/local/lib/python3.11/dist-packages/instagrapi/mixins/auth.py", line 47, in pre_login_flow self.set_contact_point_prefill("prefill") File "/usr/local/lib/python3.11/dist-packages/instagrapi/mixins/auth.py", line 147, in set_contact_point_prefill return self.private_request("accounts/contact_point_prefill/", data, login=True) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/dist-packages/instagrapi/mixins/private.py", line 451, in private_request raise e File "/usr/local/lib/python3.11/dist-packages/instagrapi/mixins/private.py", line 438, in private_request self._send_private_request(endpoint, **kwargs) File "/usr/local/lib/python3.11/dist-packages/instagrapi/mixins/private.py", line 380, in _send_private_request raise ClientConnectionError( instagrapi.exceptions.ClientConnectionError: ProxyError HTTPSConnectionPool(host='i.instagram.com', port=443): Max retries exceeded with url: /api/v1/accounts/contact_point_prefill/ (Caused by ProxyError('Cannot connect to proxy.', NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x7f5c85310210>: Failed to establish a new connection: [Errno -2] Name or service not known'))) root@crm-falcon:~/InstaPy2# python falconmarketing.py [INFO]: Created session using proxy: http|https://djtjvyrj:4wyl05g6krj4@185.199.229.156:7492. Traceback (most recent call last): File "/usr/lib/python3/dist-packages/urllib3/connection.py", line 159, in _new_conn conn = connection.create_connection( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/lib/python3/dist-packages/urllib3/util/connection.py", line 61, in create_connection for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/lib/python3.11/socket.py", line 962, in getaddrinfo for res in _socket.getaddrinfo(host, port, family, type, proto, flags): ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ socket.gaierror: [Errno -2] Name or service not known

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 662, in urlopen self._prepare_proxy(conn) File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 950, in _prepare_proxy conn.connect() File "/usr/lib/python3/dist-packages/urllib3/connection.py", line 314, in connect conn = self._new_conn() ^^^^^^^^^^^^^^^^ File "/usr/lib/python3/dist-packages/urllib3/connection.py", line 171, in _new_conn raise NewConnectionError( urllib3.exceptions.NewConnectionError: <urllib3.connection.VerifiedHTTPSConnection object at 0x7f0609ab8210>: Failed to establish a new connection: [Errno -2] Name or service not known

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/usr/local/lib/python3.11/dist-packages/requests/adapters.py", line 489, in send resp = conn.urlopen( ^^^^^^^^^^^^^ File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 719, in urlopen retries = retries.increment( ^^^^^^^^^^^^^^^^^^ File "/usr/lib/python3/dist-packages/urllib3/util/retry.py", line 436, in increment raise MaxRetryError(_pool, url, error or ResponseError(cause)) urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='i.instagram.com', port=443): Max retries exceeded with url: /api/v1/accounts/contact_point_prefill/ (Caused by ProxyError('Cannot connect to proxy.', NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x7f0609ab8210>: Failed to establish a new connection: [Errno -2] Name or service not known')))

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/usr/local/lib/python3.11/dist-packages/instagrapi/mixins/private.py", line 288, in _send_private_request response = self.private.post( ^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/dist-packages/requests/sessions.py", line 635, in post return self.request("POST", url, data=data, json=json, kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/dist-packages/requests/sessions.py", line 587, in request resp = self.send(prep, send_kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/dist-packages/requests/sessions.py", line 701, in send r = adapter.send(request, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/dist-packages/requests/adapters.py", line 559, in send raise ProxyError(e, request=request) requests.exceptions.ProxyError: HTTPSConnectionPool(host='i.instagram.com', port=443): Max retries exceeded with url: /api/v1/accounts/contact_point_prefill/ (Caused by ProxyError('Cannot connect to proxy.', NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x7f0609ab8210>: Failed to establish a new connection: [Errno -2] Name or service not known')))

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/root/InstaPy2/falconmarketing.py", line 33, in session.login(username='falconmarketingfr', password='XXXX') File "/usr/local/lib/python3.11/dist-packages/instapy2/instapy2_base.py", line 27, in login logged_in = self.session.login(username=username, password=password, verification_code=verification_code) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/dist-packages/instagrapi/mixins/auth.py", line 371, in login self.pre_login_flow() File "/usr/local/lib/python3.11/dist-packages/instagrapi/mixins/auth.py", line 47, in pre_login_flow self.set_contact_point_prefill("prefill") File "/usr/local/lib/python3.11/dist-packages/instagrapi/mixins/auth.py", line 147, in set_contact_point_prefill return self.private_request("accounts/contact_point_prefill/", data, login=True) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/dist-packages/instagrapi/mixins/private.py", line 451, in private_request raise e File "/usr/local/lib/python3.11/dist-packages/instagrapi/mixins/private.py", line 438, in private_request self._send_private_request(endpoint, **kwargs) File "/usr/local/lib/python3.11/dist-packages/instagrapi/mixins/private.py", line 380, in _send_private_request raise ClientConnectionError( instagrapi.exceptions.ClientConnectionError: ProxyError HTTPSConnectionPool(host='i.instagram.com', port=443): Max retries exceeded with url: /api/v1/accounts/contact_point_prefill/ (Caused by ProxyError('Cannot connect to proxy.', NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x7f0609ab8210>: Failed to establish a new connection: [Errno -2] Name or service not known')))

jarrodnorwell commented 1 year ago

@Senooy Did you edit the proxy scheme (http|https) and username and password?

| means one or the other, you'll have to check the SSL status of the proxy and authentication if necessary.

Senooy commented 1 year ago

After checking, SSL status is good for my proxies

It has to be something with my VPS blocking the use of proxies for some reason

By the way when using it on local, Instagram located me in my exact position instead of the proxy position I writed it like this :

session = InstaPy2() session.set_proxies(proxies=['http|https://djtjvxxx:4wyl05xxxx@185.199.xxx.xx:xxxx']) session.login(username='falconxxx', password='xxxx')

jarrodnorwell commented 1 year ago

https://username:password@host:port should be what you use if https is supported. (remove http|)