1

サーバー プロキシ リクエスト。

@asyncio.coroutine
def send_async_request(method, url, data, timeout):
    with ClientSession() as session:
        response = yield from asyncio.wait_for(
            session.request(method, url, data=data), timeout=timeout
        )
        return response

すべてが応答コード 200 で機能します。500 応答コードになると、応答から json を読み取ることができません。例外 ServerDisconnectedError:

response = yield from send_async_request(request.method, url)
response_json = yield from response.json()

Traceback (most recent call last):  

File "C:\Python34\lib\site-packages\aiohttp\server.py", line 285, in start
    yield from self.handle_request(message, payload)
  File "C:\Python34\lib\site-packages\aiohttp\web.py", line 90, in handle_request
    resp = yield from handler(request)
  File "D:/projects/SeleniumGridDispatcher/trunk/application.py", line 122, in proxy_wd
    response_json = yield from response.json()
  File "C:\Python34\lib\site-packages\aiohttp\client_reqrep.py", line 764, in json
    yield from self.read()
  File "C:\Python34\lib\site-packages\aiohttp\client_reqrep.py", line 720, in read
    self._content = yield from self.content.read()
  File "C:\Python34\lib\site-packages\aiohttp\streams.py", line 486, in wrapper
    result = yield from func(self, *args, **kw)
  File "C:\Python34\lib\site-packages\aiohttp\streams.py", line 541, in read
    return (yield from super().read(n))
  File "C:\Python34\lib\site-packages\aiohttp\streams.py", line 261, in read
    block = yield from self.readany()
  File "C:\Python34\lib\site-packages\aiohttp\streams.py", line 486, in wrapper
    result = yield from func(self, *args, **kw)
  File "C:\Python34\lib\site-packages\aiohttp\streams.py", line 549, in readany
    return (yield from super().readany())
  File "C:\Python34\lib\site-packages\aiohttp\streams.py", line 284, in readany
    yield from self._waiter
  File "C:\Python34\lib\asyncio\futures.py", line 358, in __iter__
    yield self  # This tells Task to wait for completion.
  File "C:\Python34\lib\asyncio\tasks.py", line 290, in _wakeup
    future.result()
  File "C:\Python34\lib\asyncio\futures.py", line 274, in result
    raise self._exception
aiohttp.errors.ServerDisconnectedError

何が起こっていたのかを理解するのに役立ちます。Python: 3.4.4 aiohttp: 0.22.5

4

2 に答える 2

0

Content-Length500 の応答を確認してください。aiohttp が json 本体を読み込もうとしているように見えますが、本体はヘッダーで指定されたものよりも短くなっています。

于 2016-08-30T15:48:36.137 に答える