簡體   English   中英

嘗試使用 eBay 查找 sdk 和 python 時出現連接錯誤

[英]I am getting a Connection error when trying to use the eBay finding sdk with python

最近,當我嘗試與 eBay 連接以發出請求時,發現 SDK 和 python,我一直收到連接錯誤。 錯誤打印沒有 state 有什么問題。

這是我為發出 API 請求而編寫的 python 腳本。

from ebaysdk.finding import Connection as find_connect
import xmltodict

APP_ID = 'ActualID was removed-PRD-For privacy'
# keywords = input("Enter search keywords(e.g 'white board'): ")

api = find_connect(appid=APP_ID, config_file=None,  siteid="EBAY-ENCA")
request = {
        'keywords': "Iphone x 64gb",
        'itemFilter': [
            {'name': 'Condition', 'value': 'Used'},
            {'name': 'currency', 'value': 'CAD'},
            {'name': 'minPrice', 'value': 100.0}
        ],
        'paginationInput': {
            'entriesPerPage': 100,
            'pageNumber': 10
        },
    }

resp = api.execute('findItemsByKeywords', request).dict() # Change from XML to dictionary

當我運行腳本時,我得到了這個錯誤

Traceback (most recent call last):
  File "C:\Users\Lase.Adebayo\AppData\Local\Programs\Python\Python38-32\lib\site-packages\urllib3\connectionpool.py", line 665, in urlopen
    httplib_response = self._make_request(
  File "C:\Users\Lase.Adebayo\AppData\Local\Programs\Python\Python38-32\lib\site-packages\urllib3\connectionpool.py", line 421, in _make_request
    six.raise_from(e, None)
  File "<string>", line 3, in raise_from
  File "C:\Users\Lase.Adebayo\AppData\Local\Programs\Python\Python38-32\lib\site-packages\urllib3\connectionpool.py", line 416, in _make_request
    httplib_response = conn.getresponse()
  File "C:\Users\Lase.Adebayo\AppData\Local\Programs\Python\Python38-32\lib\http\client.py", line 1322, in getresponse
    response.begin()
  File "C:\Users\Lase.Adebayo\AppData\Local\Programs\Python\Python38-32\lib\http\client.py", line 303, in begin
    version, status, reason = self._read_status()
  File "C:\Users\Lase.Adebayo\AppData\Local\Programs\Python\Python38-32\lib\http\client.py", line 264, in _read_status
    line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1")
  File "C:\Users\Lase.Adebayo\AppData\Local\Programs\Python\Python38-32\lib\socket.py", line 669, in readinto
    return self._sock.recv_into(b)
ConnectionResetError: [WinError 10054] An existing connection was forcibly closed by the remote host

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\Lase.Adebayo\AppData\Local\Programs\Python\Python38-32\lib\site-packages\requests\adapters.py", line 439, in send
    resp = conn.urlopen(
  File "C:\Users\Lase.Adebayo\AppData\Local\Programs\Python\Python38-32\lib\site-packages\urllib3\connectionpool.py", line 719, in urlopen
    retries = retries.increment(
  File "C:\Users\Lase.Adebayo\AppData\Local\Programs\Python\Python38-32\lib\site-packages\urllib3\util\retry.py", line 400, in increment
    raise six.reraise(type(error), error, _stacktrace)
  File "C:\Users\Lase.Adebayo\AppData\Local\Programs\Python\Python38-32\lib\site-packages\urllib3\packages\six.py", line 734, in reraise
    raise value.with_traceback(tb)
  File "C:\Users\Lase.Adebayo\AppData\Local\Programs\Python\Python38-32\lib\site-packages\urllib3\connectionpool.py", line 665, in urlopen
    httplib_response = self._make_request(
  File "C:\Users\Lase.Adebayo\AppData\Local\Programs\Python\Python38-32\lib\site-packages\urllib3\connectionpool.py", line 421, in _make_request
    six.raise_from(e, None)
  File "<string>", line 3, in raise_from
  File "C:\Users\Lase.Adebayo\AppData\Local\Programs\Python\Python38-32\lib\site-packages\urllib3\connectionpool.py", line 416, in _make_request
    httplib_response = conn.getresponse()
  File "C:\Users\Lase.Adebayo\AppData\Local\Programs\Python\Python38-32\lib\http\client.py", line 1322, in getresponse
    response.begin()
  File "C:\Users\Lase.Adebayo\AppData\Local\Programs\Python\Python38-32\lib\http\client.py", line 303, in begin
    version, status, reason = self._read_status()
  File "C:\Users\Lase.Adebayo\AppData\Local\Programs\Python\Python38-32\lib\http\client.py", line 264, in _read_status
    line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1")
  File "C:\Users\Lase.Adebayo\AppData\Local\Programs\Python\Python38-32\lib\socket.py", line 669, in readinto
    return self._sock.recv_into(b)
urllib3.exceptions.ProtocolError: ('Connection aborted.', ConnectionResetError(10054, 'An existing connection was forcibly closed by the remote host', None, 10054, None))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:/Users/Lase.Adebayo/PycharmProjects/eBay Data Collector/eBayCaller/ebay scripts/ebayxml.py", line 24, in <module>
    resp = api.execute('findItemsByKeywords', request).dict() # Change from XML to dictionary
  File "C:\Users\Lase.Adebayo\AppData\Local\Programs\Python\Python38-32\lib\site-packages\ebaysdk\connection.py", line 123, in execute
    self.execute_request()
  File "C:\Users\Lase.Adebayo\AppData\Local\Programs\Python\Python38-32\lib\site-packages\ebaysdk\connection.py", line 189, in execute_request
    self.response = self.session.send(self.request,
  File "C:\Users\Lase.Adebayo\AppData\Local\Programs\Python\Python38-32\lib\site-packages\requests\sessions.py", line 646, in send
    r = adapter.send(request, **kwargs)
  File "C:\Users\Lase.Adebayo\AppData\Local\Programs\Python\Python38-32\lib\site-packages\requests\adapters.py", line 498, in send
    raise ConnectionError(err, request=request)
requests.exceptions.ConnectionError: ('Connection aborted.', ConnectionResetError(10054, 'An existing connection was forcibly closed by the remote host', None, 10054, None))

相同的代碼大約在兩周前工作。

似乎 python sdk 開發人員尚未將代碼從 HTTP 更改為 Z0E8433F9A404F1F3BA601C14B02。 您可以使用 YAML 配置文件來指定 https 請求。

svcs.ebay.com:
    appid: YOUR_APP_ID
    https: 1

如果您想通過 https 對 SDK 或更早版本的 2.1.5 版本進行調用,則需要 YAML 配置。 2.2.0+ 將強制所有調用 https,因為 eBay 已完全遷移到 https。

https://github.com/timotheus/ebaysdk-python/wiki/YAML-Configuration

如果不想使用 YAML,可以在 api_call 中添加一個參數:

例如,這是我在 Python 中不使用 YAML 時使用的代碼:

api = finding(https=True, appid='your_app_id', config_file = None) 

或者你可以設置 https=1

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM