我尝试基于此示例向channeladvisor API发出批处理请求:

https://developer.channeladvisor.com/batch-requests/update-quantity-on-three-items-using-the-unshipped-update-type

我的请求看起来像这样:

POST https://api.channeladvisor.com/v1/$batch?access_token=xxxxxx
    Content-Length: 1307
    Content-Type: multipart/mixed; boundary=938fabdd69a541beb904b703514f8bc3

    --batch
    Content-Type: multipart/mixed; boundary=938fabdd69a541beb904b703514f8bc3
    --938fabdd69a541beb904b703514f8bc3
    Content-Type: application/http
    Content-Transfer-Encoding: binary
    Content-ID: 1

    POST https://api.channeladvisor.com/V1/Products(227657)/UpdateQuantity HTTP/HTTPS 1.1
    Content-Type: application/json

    {"Value": {"UpdateType": "UnShipped", "Updates": [{"DistributionCenterID": 1, "Quantity": 2}]}}
    --938fabdd69a541beb904b703514f8bc3
    Content-Type: application/http
    Content-Transfer-Encoding: binary
    Content-ID: 2

    POST https://api.channeladvisor.com/V1/Products(227658)/UpdateQuantity HTTP/HTTPS 1.1
    Content-Type: application/json

    {"Value": {"UpdateType": "UnShipped", "Updates": [{"DistributionCenterID": 1, "Quantity": 2}]}}
    --938fabdd69a541beb904b703514f8bc3
    Content-Type: application/http
    Content-Transfer-Encoding: binary
    Content-ID: 3

    POST https://api.channeladvisor.com/V1/Products(227659)/UpdateQuantity HTTP/HTTPS 1.1
    Content-Type: application/json

    {"Value": {"UpdateType": "UnShipped", "Updates": [{"DistributionCenterID": 1, "Quantity": 2}]}}
    --938fabdd69a541beb904b703514f8bc3--
    --batch

我正在使用python请求库和一点点黑客来实现这一点 . 使用邮差时,这很好用 . 我得到204状态 .

当我用python尝试它时:

data = {
  'Value':{
    'UpdateType': 'UnShipped',
    'Updates': [{
        'DistributionCenterID': 1,
        'Quantity': 2
    }]
  }
}
headers = {
    'Content-Type': 'application/json'
}
commands = []
commands.append(requests.Request('POST', 'https://api.channeladvisor.com/V1/Products(227657)/UpdateQuantity HTTP/1.1', json=data, headers=headers))
commands.append(requests.Request('POST', 'https://api.channeladvisor.com/V1/Products(227658)/UpdateQuantity HTTP/1.1', json=data, headers=headers))
commands.append(requests.Request('POST', 'https://api.channeladvisor.com/V1/Products(227659)/UpdateQuantity HTTP/1.1', json=data, headers=headers))
#-----------------------------------------------#


batch = BatchRequest()
files = batch.prepare_requests(commands)
r = requests.Request('POST', 'https://api.channeladvisor.com/v1/$batch?access_token='+self.access_token, files=files)
prepared = r.prepare()
prepared = batch.finalize_request(prepared)

batch.pretty_print_POST(prepared)
s = requests.Session()
resp = s.send(prepared)

我明白了:

Traceback (most recent call last):
      File "/usr/local/lib/python3.6/site-packages/urllib3/connectionpool.py", line 601, in urlopen
        chunked=chunked)
      File "/usr/local/lib/python3.6/site-packages/urllib3/connectionpool.py", line 387, in _make_request
        six.raise_from(e, None)
      File "", line 2, in raise_from
      File "/usr/local/lib/python3.6/site-packages/urllib3/connectionpool.py", line 383, in _make_request
        httplib_response = conn.getresponse()
      File "/usr/local/Cellar/python/3.6.5/Frameworks/Python.framework/Versions/3.6/lib/python3.6/http/client.py", line 1331, in getresponse
        response.begin()
      File "/usr/local/Cellar/python/3.6.5/Frameworks/Python.framework/Versions/3.6/lib/python3.6/http/client.py", line 297, in begin
        version, status, reason = self._read_status()
      File "/usr/local/Cellar/python/3.6.5/Frameworks/Python.framework/Versions/3.6/lib/python3.6/http/client.py", line 258, in _read_status
        line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1")
      File "/usr/local/Cellar/python/3.6.5/Frameworks/Python.framework/Versions/3.6/lib/python3.6/socket.py", line 586, in readinto
        return self._sock.recv_into(b)
      File "/usr/local/lib/python3.6/site-packages/urllib3/contrib/pyopenssl.py", line 285, in recv_into
        raise SocketError(str(e))
    OSError: (54, 'ECONNRESET')

    During handling of the above exception, another exception occurred:

    Traceback (most recent call last):
      File "/usr/local/lib/python3.6/site-packages/requests/adapters.py", line 440, in send
        timeout=timeout
      File "/usr/local/lib/python3.6/site-packages/urllib3/connectionpool.py", line 639, in urlopen
        _stacktrace=sys.exc_info()[2])
      File "/usr/local/lib/python3.6/site-packages/urllib3/util/retry.py", line 357, in increment
        raise six.reraise(type(error), error, _stacktrace)
      File "/usr/local/lib/python3.6/site-packages/urllib3/packages/six.py", line 685, in reraise
        raise value.with_traceback(tb)
      File "/usr/local/lib/python3.6/site-packages/urllib3/connectionpool.py", line 601, in urlopen
        chunked=chunked)
      File "/usr/local/lib/python3.6/site-packages/urllib3/connectionpool.py", line 387, in _make_request
        six.raise_from(e, None)
      File "", line 2, in raise_from
      File "/usr/local/lib/python3.6/site-packages/urllib3/connectionpool.py", line 383, in _make_request
        httplib_response = conn.getresponse()
      File "/usr/local/Cellar/python/3.6.5/Frameworks/Python.framework/Versions/3.6/lib/python3.6/http/client.py", line 1331, in getresponse
        response.begin()
      File "/usr/local/Cellar/python/3.6.5/Frameworks/Python.framework/Versions/3.6/lib/python3.6/http/client.py", line 297, in begin
        version, status, reason = self._read_status()
      File "/usr/local/Cellar/python/3.6.5/Frameworks/Python.framework/Versions/3.6/lib/python3.6/http/client.py", line 258, in _read_status
        line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1")
      File "/usr/local/Cellar/python/3.6.5/Frameworks/Python.framework/Versions/3.6/lib/python3.6/socket.py", line 586, in readinto
        return self._sock.recv_into(b)
      File "/usr/local/lib/python3.6/site-packages/urllib3/contrib/pyopenssl.py", line 285, in recv_into
        raise SocketError(str(e))
    urllib3.exceptions.ProtocolError: ('Connection aborted.', OSError("(54, 'ECONNRESET')",))

    During handling of the above exception, another exception occurred:

    Traceback (most recent call last):
      File "channel.py", line 157, in 
        products.batchStockUpload()
      File "channel.py", line 146, in batchStockUpload
        resp = s.send(prepared, verify=True) #verify='/usr/local/Cellar/openssl/1.0.2o_1'
      File "/usr/local/lib/python3.6/site-packages/requests/sessions.py", line 618, in send
        r = adapter.send(request, **kwargs)
      File "/usr/local/lib/python3.6/site-packages/requests/adapters.py", line 490, in send
        raise ConnectionError(err, request=request)
    requests.exceptions.ConnectionError: ('Connection aborted.', OSError("(54, 'ECONNRESET')",))

我尝试了一切,真的绝望地问这个问题?感谢帮助