I have been using Tweepy with Python 3 and needed to get the followers list of some famous handles for my learning.
Here is my code:
import tweepy
from tweepy import OAuthHandler
import time
consumer_key = 'x
consumer_secret = 'y'
access_token = 'a'
access_secret = 'b'
auth = OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_secret)
api = tweepy.API(auth)
users = tweepy.Cursor(api.followers, screen_name='realmadrid', count=200).items()
while True:
try:
user = next(users)
except tweepy.TweepError:
time.sleep(60 * 15)
user = next(users)
except StopIteration:
break
with open('BJP_Followers3.txt', 'a') as f:
f.write(user.screen_name)
f.write('\n')
print(user.screen_name)
Now, as we know I can get at most 3000 followers in given 15 mins time so I make it to sleep for 15 mins and then it runs and fetches another 3000 followers.
Now after this I got the following error:
Traceback (most recent call last):
File "C:\Python34\lib\site-packages\requests\packages\urllib3\connectionpool.py", line 594, in urlopen
chunked=chunked)
File "C:\Python34\lib\site-packages\requests\packages\urllib3\connectionpool.py", line 391, in _make_request
six.raise_from(e, None)
File "<string>", line 2, in raise_from
File "C:\Python34\lib\site-packages\requests\packages\urllib3\connectionpool.py", line 387, in _make_request
httplib_response = conn.getresponse()
File "C:\Python34\lib\http\client.py", line 1171, in getresponse
response.begin()
File "C:\Python34\lib\http\client.py", line 351, in begin
version, status, reason = self._read_status()
File "C:\Python34\lib\http\client.py", line 313, in _read_status
line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1")
File "C:\Python34\lib\socket.py", line 374, in readinto
return self._sock.recv_into(b)
File "C:\Python34\lib\ssl.py", line 751, in recv_into
return self.read(nbytes, buffer)
File "C:\Python34\lib\ssl.py", line 623, in read
v = self._sslobj.read(len, buffer)
ConnectionAbortedError: [WinError 10053] An established connection was aborted by the software in your host machine
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Python34\lib\site-packages\requests\adapters.py", line 423, in send
timeout=timeout
File "C:\Python34\lib\site-packages\requests\packages\urllib3\connectionpool.py", line 643, in urlopen
_stacktrace=sys.exc_info()[2])
File "C:\Python34\lib\site-packages\requests\packages\urllib3\util\retry.py", line 334, in increment
raise six.reraise(type(error), error, _stacktrace)
File "C:\Python34\lib\site-packages\requests\packages\urllib3\packages\six.py", line 685, in reraise
raise value.with_traceback(tb)
File "C:\Python34\lib\site-packages\requests\packages\urllib3\connectionpool.py", line 594, in urlopen
chunked=chunked)
File "C:\Python34\lib\site-packages\requests\packages\urllib3\connectionpool.py", line 391, in _make_request
six.raise_from(e, None)
File "<string>", line 2, in raise_from
File "C:\Python34\lib\site-packages\requests\packages\urllib3\connectionpool.py", line 387, in _make_request
httplib_response = conn.getresponse()
File "C:\Python34\lib\http\client.py", line 1171, in getresponse
response.begin()
File "C:\Python34\lib\http\client.py", line 351, in begin
version, status, reason = self._read_status()
File "C:\Python34\lib\http\client.py", line 313, in _read_status
line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1")
File "C:\Python34\lib\socket.py", line 374, in readinto
return self._sock.recv_into(b)
File "C:\Python34\lib\ssl.py", line 751, in recv_into
return self.read(nbytes, buffer)
File "C:\Python34\lib\ssl.py", line 623, in read
v = self._sslobj.read(len, buffer)
requests.packages.urllib3.exceptions.ProtocolError: ('Connection aborted.', ConnectionAbortedError(10053,
'An established connection was aborted by the software in your host machine', None, 10053, None))
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Python34\lib\site-packages\tweepy-3.6.0-py3.4.egg\tweepy\binder.py", line 187, in execute
proxies=self.api.proxy)
File "C:\Python34\lib\site-packages\requests\sessions.py", line 488, in request
resp = self.send(prep, **send_kwargs)
File "C:\Python34\lib\site-packages\requests\sessions.py", line 609, in send
r = adapter.send(request, **kwargs)
File "C:\Python34\lib\site-packages\requests\adapters.py", line 473, in send
raise ConnectionError(err, request=request)
requests.exceptions.ConnectionError: ('Connection aborted.', ConnectionAbortedError(10053,
'An established connection was aborted by the software in your host machine', None, 10053, None))
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "E:\python\MB\Data Mining\timeline.py", line 21, in <module>
user = next(users)
File "C:\Python34\lib\site-packages\tweepy-3.6.0-py3.4.egg\tweepy\cursor.py", line 49, in __next__
return self.next()
File "C:\Python34\lib\site-packages\tweepy-3.6.0-py3.4.egg\tweepy\cursor.py", line 197, in next
self.current_page = self.page_iterator.next()
File "C:\Python34\lib\site-packages\tweepy-3.6.0-py3.4.egg\tweepy\cursor.py", line 75, in next
**self.kargs)
File "C:\Python34\lib\site-packages\tweepy-3.6.0-py3.4.egg\tweepy\binder.py", line 245, in _call
return method.execute()
File "C:\Python34\lib\site-packages\tweepy-3.6.0-py3.4.egg\tweepy\binder.py", line 189, in execute
raise TweepError('Failed to send request: %s' % e)
tweepy.error.TweepError: Failed to send request: ('Connection aborted.', ConnectionAbortedError(10053,
'An established connection was aborted by the software in your host machine', None, 10053, None))
Now, I want to know the reason as well as a solution for this problem I am facing.
Related
I have a python script in a docker that runs and collects data from an api on a loop.
`for idx, items in enumerate(SearchList):
#get access token
access_token = GetPricingAccTok()
#request id to get results
reqid = RequestIdCompSearch(items, access_token)
#api to get results by doing a while loop appending results together till api returns 100% as completed percentage
Result = GetReqResults(reqid, access_token)
Pricings = GetPricingDict(Result)
filenamepricing = "pricinghistory/CorrectFormat/Pricings_Data_{idn}_{ts}.json".format(
idn = idx,
ts= dt.datetime.now().isoformat()
)
GetAzContainer().upload_blob(
name=filenamepricing,
data=json.dumps(obj= Pricings, indent=4),
blob_type='BlockBlob'
)
`
When i run and test this code locally on my windows machine it works well without an issue and completes the requests
but in the docker on azure container instance it then returns an error showing that the connection has timed out. Not sure what the difference is between the running it locally and in the docker that i then recieve this error.
I have tried addinng this code at the start
import socket
from urllib3.connection import HTTPConnection
HTTPConnection.default_socket_options =(HTTPConnection.default_socket_options + [
(socket.SOL_SOCKET, socket.SO_KEEPALIVE, 1) #Enables the feature
,(socket.SOL_TCP, socket.TCP_KEEPIDLE, 45) #Overrides the time when the stack willl start sending KeppAlives after no data received on a Persistent Connection
,(socket.SOL_TCP, socket.TCP_KEEPINTVL, 10) #Defines how often thoe KA will be sent between them
,(socket.SOL_TCP, socket.TCP_KEEPCNT, 60) #How many attemps will your code try if the server goes down before droping the connection.
]
)
but it still times out. showing the below error
Traceback (most recent call last):
File "/usr/local/lib/python3.8/site-packages/urllib3/connectionpool.py", line 445, in _make_request
six.raise_from(e, None)
File "<string>", line 3, in raise_from
File "/usr/local/lib/python3.8/site-packages/urllib3/connectionpool.py", line 440, in _make_request
httplib_response = conn.getresponse()
File "/usr/local/lib/python3.8/http/client.py", line 1348, in getresponse
response.begin()
File "/usr/local/lib/python3.8/http/client.py", line 316, in begin
version, status, reason = self._read_status()
File "/usr/local/lib/python3.8/http/client.py", line 277, in _read_status
line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1")
File "/usr/local/lib/python3.8/socket.py", line 669, in readinto
return self._sock.recv_into(b)
File "/usr/local/lib/python3.8/ssl.py", line 1241, in recv_into
return self.read(nbytes, buffer)
File "/usr/local/lib/python3.8/ssl.py", line 1099, in read
return self._sslobj.read(len, buffer)
TimeoutError: [Errno 110] Connection timed out
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/local/lib/python3.8/site-packages/requests/adapters.py", line 440, in send
resp = conn.urlopen(
File "/usr/local/lib/python3.8/site-packages/urllib3/connectionpool.py", line 755, in urlopen
retries = retries.increment(
File "/usr/local/lib/python3.8/site-packages/urllib3/util/retry.py", line 532, in increment
raise six.reraise(type(error), error, _stacktrace)
File "/usr/local/lib/python3.8/site-packages/urllib3/packages/six.py", line 770, in reraise
raise value
File "/usr/local/lib/python3.8/site-packages/urllib3/connectionpool.py", line 699, in urlopen
httplib_response = self._make_request(
File "/usr/local/lib/python3.8/site-packages/urllib3/connectionpool.py", line 447, in _make_request
self._raise_timeout(err=e, url=url, timeout_value=read_timeout)
File "/usr/local/lib/python3.8/site-packages/urllib3/connectionpool.py", line 353, in _raise_timeout
raise ReadTimeoutError(
urllib3.exceptions.ReadTimeoutError: HTTPSConnectionPool(host='service.xxx.com', port=443): Read timed out. (read timeout=None)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "src/script.py", line 298, in <module>
reqid = RequestIdCompSearch(items, access_token)
File "src/script.py", line 111, in RequestIdCompSearch
InitResp =rq.post( ReqUrl, headers= ReqHead, data=Jsondata)
File "/usr/local/lib/python3.8/site-packages/requests/api.py", line 117, in post
return request('post', url, data=data, json=json, **kwargs)
File "/usr/local/lib/python3.8/site-packages/requests/api.py", line 61, in request
return session.request(method=method, url=url, **kwargs)
File "/usr/local/lib/python3.8/site-packages/requests/sessions.py", line 529, in request
resp = self.send(prep, **send_kwargs)
File "/usr/local/lib/python3.8/site-packages/requests/sessions.py", line 645, in send
r = adapter.send(request, **kwargs)
File "/usr/local/lib/python3.8/site-packages/requests/adapters.py", line 532, in send
raise ReadTimeout(e, request=request)
requests.exceptions.ReadTimeout: HTTPSConnectionPool(host='service.xxxx.com', port=443): Read timed out. (read timeout=None)
I have a kubernetes cluster (on GKE) which runs tornado.web.Application server, that calls heavy dask.distributed calculations on that cluster.
Now I want to test my server, and send it multiple requests at once, to see if it handles those requests as it should.
When I'm sending only one request, it does everything and behaves as expected, no matter how big the request is.
But when I send more than one request, after like 5 minutes (I also tried on server side just to sleep, without making any calculations and got the same results), I get the following:
Traceback (most recent call last):
File "/home/michael/anaconda3/lib/python3.7/site-packages/urllib3/connectionpool.py", line 706, in urlopen
chunked=chunked,
File "/home/michael/anaconda3/lib/python3.7/site-packages/urllib3/connectionpool.py", line 445, in _make_request
six.raise_from(e, None)
File "<string>", line 3, in raise_from
File "/home/michael/anaconda3/lib/python3.7/site-packages/urllib3/connectionpool.py", line 440, in _make_request
httplib_response = conn.getresponse()
File "/home/michael/anaconda3/lib/python3.7/http/client.py", line 1354, in getresponse
response.begin()
File "/home/michael/anaconda3/lib/python3.7/http/client.py", line 306, in begin
version, status, reason = self._read_status()
File "/home/michael/anaconda3/lib/python3.7/http/client.py", line 267, in _read_status
line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1")
File "/home/michael/anaconda3/lib/python3.7/socket.py", line 589, in readinto
return self._sock.recv_into(b)
ConnectionResetError: [Errno 104] Connection reset by peer
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/michael/anaconda3/lib/python3.7/site-packages/requests/adapters.py", line 449, in send
timeout=timeout
File "/home/michael/anaconda3/lib/python3.7/site-packages/urllib3/connectionpool.py", line 756, in urlopen
method, url, error=e, _pool=self, _stacktrace=sys.exc_info()[2]
File "/home/michael/anaconda3/lib/python3.7/site-packages/urllib3/util/retry.py", line 531, in increment
raise six.reraise(type(error), error, _stacktrace)
File "/home/michael/anaconda3/lib/python3.7/site-packages/urllib3/packages/six.py", line 734, in reraise
raise value.with_traceback(tb)
File "/home/michael/anaconda3/lib/python3.7/site-packages/urllib3/connectionpool.py", line 706, in urlopen
chunked=chunked,
File "/home/michael/anaconda3/lib/python3.7/site-packages/urllib3/connectionpool.py", line 445, in _make_request
six.raise_from(e, None)
File "<string>", line 3, in raise_from
File "/home/michael/anaconda3/lib/python3.7/site-packages/urllib3/connectionpool.py", line 440, in _make_request
httplib_response = conn.getresponse()
File "/home/michael/anaconda3/lib/python3.7/http/client.py", line 1354, in getresponse
response.begin()
File "/home/michael/anaconda3/lib/python3.7/http/client.py", line 306, in begin
version, status, reason = self._read_status()
File "/home/michael/anaconda3/lib/python3.7/http/client.py", line 267, in _read_status
line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1")
File "/home/michael/anaconda3/lib/python3.7/socket.py", line 589, in readinto
return self._sock.recv_into(b)
urllib3.exceptions.ProtocolError: ('Connection aborted.', ConnectionResetError(104, 'Connection reset by peer'))
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/michael/anaconda3/lib/python3.7/threading.py", line 926, in _bootstrap_inner
self.run()
File "/home/michael/anaconda3/lib/python3.7/threading.py", line 870, in run
self._target(*self._args, **self._kwargs)
File "<ipython-input-4-ce4ad22684d3>", line 24, in fire
response = requests.post(url, data=payload, headers=headers, timeout=3600)
File "/home/michael/anaconda3/lib/python3.7/site-packages/requests/api.py", line 119, in post
return request('post', url, data=data, json=json, **kwargs)
File "/home/michael/anaconda3/lib/python3.7/site-packages/requests/api.py", line 61, in request
return session.request(method=method, url=url, **kwargs)
File "/home/michael/anaconda3/lib/python3.7/site-packages/requests/sessions.py", line 542, in request
resp = self.send(prep, **send_kwargs)
File "/home/michael/anaconda3/lib/python3.7/site-packages/requests/sessions.py", line 655, in send
r = adapter.send(request, **kwargs)
File "/home/michael/anaconda3/lib/python3.7/site-packages/requests/adapters.py", line 498, in send
raise ConnectionError(err, request=request)
requests.exceptions.ConnectionError: ('Connection aborted.', ConnectionResetError(104, 'Connection reset by peer'))
And none of the requests returns.
How can I get the behaviour I need, without these errors?
I need a server that can handle many requests, and to test it from my computer.
I'm fetching OHLCV data from Binance via Binance api on AWS-EC2.
But sometime(once a couple of days) error "104, 'ECONNRESET'" occur and program stop.
The program written in Python3.7.3 and run on AWS-EC2
The code is following. But this code couldn't continue.
I want to continue the program running when any api or connection error occured.
How should I handle this error ?
while True:
..............
try :
klines = client.get_historical_klines(ticker_symbol, Client.KLINE_INTERVAL_1MINUTE, _from_str, _until_str)
except BinanceAPIException as e:
print(e)
print('Something went wrong. Error occured at %s. Wait for 1 hour.' % (datetime.datetime.now().astimezone(timezone('UTC'))))
sleep(3600)
continue
..............
All error massege are following.
Traceback (most recent call last):
File
"/home/ec2-user/.pyenv/versions/3.7.3/lib/python3.7/site-packages/urllib3/connectionpool.py",
line 600, in urlopen
chunked=chunked) File "/home/ec2-user/.pyenv/versions/3.7.3/lib/python3.7/site-packages/urllib3/connectionpool.py",
line 384, in _make_request
six.raise_from(e, None) File "", line 2, in raise_from File
"/home/ec2-user/.pyenv/versions/3.7.3/lib/python3.7/site-packages/urllib3/connectionpool.py",
line 380, in _make_request
httplib_response = conn.getresponse() File "/home/ec2-user/.pyenv/versions/3.7.3/lib/python3.7/http/client.py",
line 1321, in getresponse
response.begin() File "/home/ec2-user/.pyenv/versions/3.7.3/lib/python3.7/http/client.py",
line 296, in begin
version, status, reason = self._read_status() File "/home/ec2-user/.pyenv/versions/3.7.3/lib/python3.7/http/client.py",
line 257, in _read_status
line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1") File "/home/ec2-user/.pyenv/versions/3.7.3/lib/python3.7/socket.py", line
589, in readinto
return self._sock.recv_into(b) File "/home/ec2-user/.pyenv/versions/3.7.3/lib/python3.7/site-packages/urllib3/contrib/pyopenssl.py",
line 312, in recv_into
return self.recv_into(*args, **kwargs) File "/home/ec2-user/.pyenv/versions/3.7.3/lib/python3.7/site-packages/urllib3/contrib/pyopenssl.py",
line 302, in recv_into
raise SocketError(str(e)) OSError: (104, 'ECONNRESET')
During handling of the above exception, another exception occurred:
Traceback (most recent call last): File
"/home/ec2-user/.pyenv/versions/3.7.3/lib/python3.7/site-packages/requests/adapters.py",
line 449, in send
timeout=timeout File "/home/ec2-user/.pyenv/versions/3.7.3/lib/python3.7/site-packages/urllib3/connectionpool.py",
line 638, in urlopen
_stacktrace=sys.exc_info()[2]) File "/home/ec2-user/.pyenv/versions/3.7.3/lib/python3.7/site-packages/urllib3/util/retry.py",
line 368, in increment
raise six.reraise(type(error), error, _stacktrace) File "/home/ec2-user/.pyenv/versions/3.7.3/lib/python3.7/site-packages/urllib3/packages/six.py",
line 685, in reraise
raise value.with_traceback(tb) File "/home/ec2-user/.pyenv/versions/3.7.3/lib/python3.7/site-packages/urllib3/connectionpool.py",
line 600, in urlopen
chunked=chunked) File "/home/ec2-user/.pyenv/versions/3.7.3/lib/python3.7/site-packages/urllib3/connectionpool.py",
line 384, in _make_request
six.raise_from(e, None) File "", line 2, in raise_from File
"/home/ec2-user/.pyenv/versions/3.7.3/lib/python3.7/site-packages/urllib3/connectionpool.py",
line 380, in _make_request
httplib_response = conn.getresponse() File "/home/ec2-user/.pyenv/versions/3.7.3/lib/python3.7/http/client.py",
line 1321, in getresponse
response.begin() File "/home/ec2-user/.pyenv/versions/3.7.3/lib/python3.7/http/client.py",
line 296, in begin
version, status, reason = self._read_status() File "/home/ec2-user/.pyenv/versions/3.7.3/lib/python3.7/http/client.py",
line 257, in _read_status
line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1") File "/home/ec2-user/.pyenv/versions/3.7.3/lib/python3.7/socket.py", line
589, in readinto
return self._sock.recv_into(b) File "/home/ec2-user/.pyenv/versions/3.7.3/lib/python3.7/site-packages/urllib3/contrib/pyopenssl.py",
line 312, in recv_into
return self.recv_into(*args, **kwargs) File "/home/ec2-user/.pyenv/versions/3.7.3/lib/python3.7/site-packages/urllib3/contrib/pyopenssl.py",
line 302, in recv_into
raise SocketError(str(e)) urllib3.exceptions.ProtocolError: ('Connection aborted.', OSError("(104, 'ECONNRESET')"))
During handling of the above exception, another exception occurred:
Traceback (most recent call last): File
"BTC_USDT_BINANCE_minutes.py", line 54, in
klines = client.get_historical_klines(ticker_symbol, Client.KLINE_INTERVAL_1MINUTE, _from_str, _until_str) File
"/home/ec2-user/.pyenv/versions/3.7.3/lib/python3.7/site-packages/binance/client.py",
line 765, in get_historical_klines
first_valid_ts = self._get_earliest_valid_timestamp(symbol, interval) File
"/home/ec2-user/.pyenv/versions/3.7.3/lib/python3.7/site-packages/binance/client.py",
line 723, in _get_earliest_valid_timestamp
endTime=None File "/home/ec2-user/.pyenv/versions/3.7.3/lib/python3.7/site-packages/binance/client.py",
line 705, in get_klines
return self._get('klines', data=params) File "/home/ec2-user/.pyenv/versions/3.7.3/lib/python3.7/site-packages/binance/client.py",
line 207, in _get
return self._request_api('get', path, signed, version, **kwargs) File
"/home/ec2-user/.pyenv/versions/3.7.3/lib/python3.7/site-packages/binance/client.py",
line 181, in _request_api
return self._request(method, uri, signed, **kwargs) File "/home/ec2-user/.pyenv/versions/3.7.3/lib/python3.7/site-packages/binance/client.py",
line 175, in _request
response = getattr(self.session, method)(uri, **kwargs) File "/home/ec2-user/.pyenv/versions/3.7.3/lib/python3.7/site-packages/requests/sessions.py",
line 546, in get
return self.request('GET', url, **kwargs) File "/home/ec2-user/.pyenv/versions/3.7.3/lib/python3.7/site-packages/requests/sessions.py",
line 533, in request
resp = self.send(prep, **send_kwargs) File "/home/ec2-user/.pyenv/versions/3.7.3/lib/python3.7/site-packages/requests/sessions.py",
line 646, in send
r = adapter.send(request, **kwargs) File "/home/ec2-user/.pyenv/versions/3.7.3/lib/python3.7/site-packages/requests/adapters.py",
line 498, in send
raise ConnectionError(err, request=request) requests.exceptions.ConnectionError: ('Connection aborted.',
OSError("(104, 'ECONNRESET')"))
Assuming that you are using python-binance module, most likely the error happens because you are trying to reuse the client after long time (server timeout). You can try to recreate the client first:
...
client = Client(api_key, api_secret)
while True:
...
try :
klines = client.get_historical_klines(ticker_symbol, Client.KLINE_INTERVAL_1MINUTE, _from_str, _until_str)
except BinanceAPIException as e:
print(e)
print('Something went wrong. Error occured at %s. Wait for 1 hour.' % (datetime.datetime.now().astimezone(timezone('UTC'))))
sleep(3600)
client = Client(api_key, api_secret)
continue
...
The reason is because the [Client][2] uses requests Session underneath which imply usage of urllib3's connection pooling. This connection pooling can not be reused after timeout.
I am writing a simply python script for vkontakte.com (vk.com). It's main task is to run constantly in background, tracking one exact group chat. When it comes to a new message in chat, script answers back on special keywords. Nothing hard. I am kinda new to python and it's connection architecture. After a random time script fails due ConnectionResetError when it comes to answer back with vk.messages.send() function. Fails completly random - might work for 9 minutes or 20 minutes, most of time fails during message send, but also fails if i leave script working for 20+ minutes time. What do i do now ? I need it to work constantly. Also i want to understand why connection fails.
main loop that tracks new messages is written like this:
for event in longpoll.listen():
if event.type == VkEventType.MESSAGE_NEW and event.to_me and event.text:
traceback of error:
Traceback (most recent call last):
File "C:\Users\XXX\AppData\Local\Programs\Python\Python37-32\lib\site-packages\urllib3\connectionpool.py", line 600, in urlopen
chunked=chunked)
File "C:\Users\XXX\AppData\Local\Programs\Python\Python37-32\lib\site-packages\urllib3\connectionpool.py", line 384, in _make_request
six.raise_from(e, None)
File "<string>", line 2, in raise_from
File "C:\Users\XXX\AppData\Local\Programs\Python\Python37-32\lib\site-packages\urllib3\connectionpool.py", line 380, in _make_request
httplib_response = conn.getresponse()
File "C:\Users\XXX\AppData\Local\Programs\Python\Python37-32\lib\http\client.py", line 1321, in getresponse
response.begin()
File "C:\Users\XXX\AppData\Local\Programs\Python\Python37-32\lib\http\client.py", line 296, in begin
version, status, reason = self._read_status()
File "C:\Users\XXX\AppData\Local\Programs\Python\Python37-32\lib\http\client.py", line 257, in _read_status
line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1")
File "C:\Users\XXX\AppData\Local\Programs\Python\Python37-32\lib\socket.py", line 589, in readinto
return self._sock.recv_into(b)
File "C:\Users\XXX\AppData\Local\Programs\Python\Python37-32\lib\ssl.py", line 1052, in recv_into
return self.read(nbytes, buffer)
File "C:\Users\XXX\AppData\Local\Programs\Python\Python37-32\lib\ssl.py", line 911, in read 17:58
return self._sslobj.read(len, buffer)
ConnectionResetError: [WinError 10054] Удаленный хост принудительно разорвал существующее подключение (remote peer forcing a connection to close)
continue of traceback:
Traceback (most recent call last):
File "C:\Users\XXX\AppData\Local\Programs\Python\Python37-32\lib\site-packages\requests\adapters.py", line 449, in send
timeout=timeout
File "C:\Users\XXX\AppData\Local\Programs\Python\Python37-32\lib\site-packages\urllib3\connectionpool.py", line 638, in urlopen
_stacktrace=sys.exc_info()[2])
File "C:\Users\XXX\AppData\Local\Programs\Python\Python37-32\lib\site-packages\urllib3\util\retry.py", line 367, in increment
raise six.reraise(type(error), error, _stacktrace)
File "C:\Users\XXX\AppData\Local\Programs\Python\Python37-32\lib\site-packages\urllib3\packages\six.py", line 685, in reraise
raise value.with_traceback(tb)
File "C:\Users\XXX\AppData\Local\Programs\Python\Python37-32\lib\site-packages\urllib3\connectionpool.py", line 600, in urlopen
chunked=chunked)
File "C:\Users\XXX\AppData\Local\Programs\Python\Python37-32\lib\site-packages\urllib3\connectionpool.py", line 384, in _make_request
six.raise_from(e, None)
File "<string>", line 2, in raise_from
File "C:\Users\XXX\AppData\Local\Programs\Python\Python37-32\lib\site-packages\urllib3\connectionpool.py", line 380, in _make_request
httplib_response = conn.getresponse()
File "C:\Users\XXX\AppData\Local\Programs\Python\Python37-32\lib\http\client.py", line 1321, in getresponse
response.begin()
File "C:\Users\XXX\AppData\Local\Programs\Python\Python37-32\lib\http\client.py", line 296, in begin
version, status, reason = self._read_status()
File "C:\Users\XXX\AppData\Local\Programs\Python\Python37-32\lib\http\client.py", line 257, in _read_status
line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1")
File "C:\Users\XXX\AppData\Local\Programs\Python\Python37-32\lib\socket.py", line 589, in readinto
return self._sock.recv_into(b)
File "C:\Users\XXX\AppData\Local\Programs\Python\Python37-32\lib\ssl.py", line 1052, in recv_into
return self.read(nbytes, buffer)
File "C:\Users\XXX\AppData\Local\Programs\Python\Python37-32\lib\ssl.py", line 911, in read
return self._sslobj.read(len, buffer)
urllib3.exceptions.ProtocolError: ('Connection aborted.', ConnectionResetError(10054, 'Удаленный хост принудительно разорвал существующее подключение', None, 10054, None))
and last one:
Traceback (most recent call last):
File "vsk_bot.py", line 37, in <module>
vk.messages.send(
File "C:\Users\XXX\AppData\Local\Programs\Python\Python37-32\lib\site-packages\vk_api\vk_api.py", line 671, in __call__
return self._vk.method(self._method, kwargs)
File "C:\Users\XXX\AppData\Local\Programs\Python\Python37-32\lib\site-packages\vk_api\vk_api.py", line 602, in method
values
File "C:\Users\XXX\AppData\Local\Programs\Python\Python37-32\lib\site-packages\requests\sessions.py", line 581, in post
return self.request('POST', url, data=data, json=json, **kwargs)
File "C:\Users\XXX\AppData\Local\Programs\Python\Python37-32\lib\site-packages\requests\sessions.py", line 533, in request
resp = self.send(prep, **send_kwargs)
File "C:\Users\XXX\AppData\Local\Programs\Python\Python37-32\lib\site-packages\requests\sessions.py", line 646, in send
r = adapter.send(request, **kwargs)
File "C:\Users\XXX\AppData\Local\Programs\Python\Python37-32\lib\site-packages\requests\adapters.py", line 498, in send
raise ConnectionError(err, request=request)
requests.exceptions.ConnectionError: ('Connection aborted.', ConnectionResetError(10054, 'Удаленный хост принудительно разорвал существующее подключение', None, 10054, None))
I'm trying to retrieve the Session ID and FetchToken like the following.
import datetime
from ebaysdk.exception import ConnectionError
from ebaysdk.trading import Connection
try:
api = Connection(appid='APP_ID',
devid='DEV_ID',
certid='CERT_ID',
config_file=None)
response = api.execute('GetSessionID') # <<===== I'm executing here to understand the response
# response = api.execute('FetchToken', runame='RUNAME')
# response = api.execute('GetSellerList', runame='RUNAME')
except ConnectionError as e:
print(e)
print(e.response.dict())
But when I execute api.execute('GetSessionID') to test, I have a connection error like this:
Traceback (most recent call last):
File "/usr/local/anaconda3/envs/ebay_api/lib/python3.6/site-packages/urllib3/connectionpool.py", line 601, in urlopen
chunked=chunked)
File "/usr/local/anaconda3/envs/ebay_api/lib/python3.6/site-packages/urllib3/connectionpool.py", line 387, in _make_request
six.raise_from(e, None)
File "<string>", line 2, in raise_from
File "/usr/local/anaconda3/envs/ebay_api/lib/python3.6/site-packages/urllib3/connectionpool.py", line 383, in _make_request
httplib_response = conn.getresponse()
File "/usr/local/anaconda3/envs/ebay_api/lib/python3.6/http/client.py", line 1331, in getresponse
response.begin()
File "/usr/local/anaconda3/envs/ebay_api/lib/python3.6/http/client.py", line 297, in begin
version, status, reason = self._read_status()
File "/usr/local/anaconda3/envs/ebay_api/lib/python3.6/http/client.py", line 258, in _read_status
line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1")
File "/usr/local/anaconda3/envs/ebay_api/lib/python3.6/socket.py", line 586, in readinto
return self._sock.recv_into(b)
File "/usr/local/anaconda3/envs/ebay_api/lib/python3.6/ssl.py", line 1009, in recv_into
return self.read(nbytes, buffer)
File "/usr/local/anaconda3/envs/ebay_api/lib/python3.6/ssl.py", line 871, in read
return self._sslobj.read(len, buffer)
File "/usr/local/anaconda3/envs/ebay_api/lib/python3.6/ssl.py", line 631, in read
v = self._sslobj.read(len, buffer)
ConnectionResetError: [Errno 54] Connection reset by peer
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/local/anaconda3/envs/ebay_api/lib/python3.6/site-packages/requests/adapters.py", line 440, in send
timeout=timeout
File "/usr/local/anaconda3/envs/ebay_api/lib/python3.6/site-packages/urllib3/connectionpool.py", line 639, in urlopen
_stacktrace=sys.exc_info()[2])
File "/usr/local/anaconda3/envs/ebay_api/lib/python3.6/site-packages/urllib3/util/retry.py", line 357, in increment
raise six.reraise(type(error), error, _stacktrace)
File "/usr/local/anaconda3/envs/ebay_api/lib/python3.6/site-packages/urllib3/packages/six.py", line 685, in reraise
raise value.with_traceback(tb)
File "/usr/local/anaconda3/envs/ebay_api/lib/python3.6/site-packages/urllib3/connectionpool.py", line 601, in urlopen
chunked=chunked)
File "/usr/local/anaconda3/envs/ebay_api/lib/python3.6/site-packages/urllib3/connectionpool.py", line 387, in _make_request
six.raise_from(e, None)
File "<string>", line 2, in raise_from
File "/usr/local/anaconda3/envs/ebay_api/lib/python3.6/site-packages/urllib3/connectionpool.py", line 383, in _make_request
httplib_response = conn.getresponse()
File "/usr/local/anaconda3/envs/ebay_api/lib/python3.6/http/client.py", line 1331, in getresponse
response.begin()
File "/usr/local/anaconda3/envs/ebay_api/lib/python3.6/http/client.py", line 297, in begin
version, status, reason = self._read_status()
File "/usr/local/anaconda3/envs/ebay_api/lib/python3.6/http/client.py", line 258, in _read_status
line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1")
File "/usr/local/anaconda3/envs/ebay_api/lib/python3.6/socket.py", line 586, in readinto
return self._sock.recv_into(b)
File "/usr/local/anaconda3/envs/ebay_api/lib/python3.6/ssl.py", line 1009, in recv_into
return self.read(nbytes, buffer)
File "/usr/local/anaconda3/envs/ebay_api/lib/python3.6/ssl.py", line 871, in read
return self._sslobj.read(len, buffer)
File "/usr/local/anaconda3/envs/ebay_api/lib/python3.6/ssl.py", line 631, in read
v = self._sslobj.read(len, buffer)
urllib3.exceptions.ProtocolError: ('Connection aborted.', ConnectionResetError(54, 'Connection reset by peer'))
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<input>", line 1, in <module>
File "/usr/local/anaconda3/envs/ebay_api/lib/python3.6/site-packages/ebaysdk/connection.py", line 123, in execute
self.execute_request()
File "/usr/local/anaconda3/envs/ebay_api/lib/python3.6/site-packages/ebaysdk/connection.py", line 193, in execute_request
allow_redirects=True
File "/usr/local/anaconda3/envs/ebay_api/lib/python3.6/site-packages/requests/sessions.py", line 618, in send
r = adapter.send(request, **kwargs)
File "/usr/local/anaconda3/envs/ebay_api/lib/python3.6/site-packages/requests/adapters.py", line 490, in send
raise ConnectionError(err, request=request)
requests.exceptions.ConnectionError: ('Connection aborted.', ConnectionResetError(54, 'Connection reset by peer'))
The idea is to retrieve the SessionID and reuse it to call FetchToken later and be able to access the other methods from Trading API. But without it working properly I can't do nothing on Trading API.
Thanks in advance.
I know this might be late, but try this in requirements.txt:
lxml
requests[security]
see: https://github.com/requests/requests/issues/3189