JSONDecodeError and ActionError while running on AWS ubuntu instance.
ParthJhunjhunwala opened this issue · 2 comments
I installed the package on my windows command prompt and the crawler worked perfectly.
I need to make it work on my AWS ubuntu instance but it throws a JSONDecodeError and ActionError.
I am running a AWS with Ubunutu release 18.04 LTS.
My commands on AWS instance were:
pip3 install pygram
python3
>>> from pygram import PyGram
>>> pygram = PyGram()
>>>profile = pygram.get_profile('eminem')
Hi @ParthJhunjhunwala, this means that Instagram does not send a proper json, usually due to arbitrary rate limits. I've just checked it and it's working for me. You might try with a different IP address or use a proxy. You can actually do the latter by just setting an environment variable: export HTTPS_PROXY="http://localhost:8080
before launching the script.
P.S. You can try with: https://www.sslproxies.org/
Hey @brunneis, I tried setting a localhost proxy as well as using proxy servers.
I get the following errors now:
Traceback (most recent call last):
File "/home/ubuntu/.local/lib/python3.6/site-packages/urllib3/connection.py", line 160, in _new_conn
(self._dns_host, self.port), self.timeout, **extra_kw
File "/home/ubuntu/.local/lib/python3.6/site-packages/urllib3/util/connection.py", line 84, in create_connection
raise err
File "/home/ubuntu/.local/lib/python3.6/site-packages/urllib3/util/connection.py", line 74, in create_connection
sock.connect(sa)
ConnectionRefusedError: [Errno 111] Connection refused
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/ubuntu/.local/lib/python3.6/site-packages/urllib3/connectionpool.py", line 667, in urlopen
self._prepare_proxy(conn)
File "/home/ubuntu/.local/lib/python3.6/site-packages/urllib3/connectionpool.py", line 930, in _prepare_proxy
conn.connect()
File "/home/ubuntu/.local/lib/python3.6/site-packages/urllib3/connection.py", line 308, in connect
conn = self._new_conn()
File "/home/ubuntu/.local/lib/python3.6/site-packages/urllib3/connection.py", line 172, in _new_conn
self, "Failed to establish a new connection: %s" % e
urllib3.exceptions.NewConnectionError: <urllib3.connection.HTTPSConnection object at 0x7fec8cd2c7f0>: Failed to establish a new connection: [Errno 111] Connection refused
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/ubuntu/.local/lib/python3.6/site-packages/requests/adapters.py", line 449, in send
timeout=timeout
File "/home/ubuntu/.local/lib/python3.6/site-packages/urllib3/connectionpool.py", line 725, in urlopen
method, url, error=e, _pool=self, _stacktrace=sys.exc_info()[2]
File "/home/ubuntu/.local/lib/python3.6/site-packages/urllib3/util/retry.py", line 439, in increment
raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='www.instagram.com', port=443): Max retries exceeded with url: /eminem/?__a=1 (Caused by ProxyError('Cannot connect to proxy.', NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x7fec8cd2c7f0>: Failed to establish a new connection: [Errno 111] Connection refused',)))
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "try.py", line 4, in <module>
profile = pygram.get_profile('eminem')
File "/home/ubuntu/.local/lib/python3.6/site-packages/pygram/pygram.py", line 78, in get_profile
profile = get_json_from_url(url, method)['graphql']['user']
File "/home/ubuntu/.local/lib/python3.6/site-packages/pygram/helper.py", line 11, in get_json_from_url
response = getattr(requests, method)(url, data=data, headers=headers)
File "/home/ubuntu/.local/lib/python3.6/site-packages/requests/api.py", line 76, in get
return request('get', url, params=params, **kwargs)
File "/home/ubuntu/.local/lib/python3.6/site-packages/requests/api.py", line 61, in request
return session.request(method=method, url=url, **kwargs)
File "/home/ubuntu/.local/lib/python3.6/site-packages/requests/sessions.py", line 530, in request
resp = self.send(prep, **send_kwargs)
File "/home/ubuntu/.local/lib/python3.6/site-packages/requests/sessions.py", line 643, in send
r = adapter.send(request, **kwargs)
File "/home/ubuntu/.local/lib/python3.6/site-packages/requests/adapters.py", line 510, in send
raise ProxyError(e, request=request)
requests.exceptions.ProxyError: HTTPSConnectionPool(host='www.instagram.com', port=443): Max retries exceeded with url: /eminem/?__a=1 (Caused by ProxyError('Cannot connect to proxy.', NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x7fec8cd2c7f0>: Failed to establish a new connection: [Errno 111] Connection refused',)))
What do I do now?