0

パイソン 3.8.8 httpx 0.18.2

これは以下の私のコードです。私は httpx&asyncio でテストしています。コードは非常に単純で例と同じですが、エラーが発生しました。

headers = {"Content-type":"text/html", "charset":"UTF-8"}
async def gethtml(url):  
    async with httpx.AsyncClient(headers=headers, verify=False) as client:
        r = await client.get(url) 
        return r.status_code
url = 'http://www.google.com'
asyncio.run(gethtml(url))

実行すると問題が発生します。

RuntimeWarning: coroutine 'current_time' was never awaited
  return float(anyio.current_time())
RuntimeWarning: Enable tracemalloc to get the object allocation traceback
Traceback (most recent call last):
  File "/Users/yilu/opt/anaconda3/lib/python3.8/site-packages/IPython/core/interactiveshell.py", line 3437, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)
  File "<ipython-input-2-12f16719e1ee>", line 1, in <module>
    runfile('/Users/yilu/Documents/7k/aaa.py', wdir='/Users/yilu/Documents/7k/')
  File "/Applications/PyCharm.app/Contents/plugins/python/helpers/pydev/_pydev_bundle/pydev_umd.py", line 197, in runfile
    pydev_imports.execfile(filename, global_vars, local_vars)  # execute the script
  File "/Applications/PyCharm.app/Contents/plugins/python/helpers/pydev/_pydev_imps/_pydev_execfile.py", line 18, in execfile
    exec(compile(contents+"\n", file, 'exec'), glob, loc)
  File "/Users/yilu/Documents/7k/aaa.py", line 53, in <module>
    asyncio.run(gethtml(url))   
  File "/Users/yilu/opt/anaconda3/lib/python3.8/asyncio/runners.py", line 44, in run
    return loop.run_until_complete(main)
  File "/Users/yilu/opt/anaconda3/lib/python3.8/asyncio/base_events.py", line 616, in run_until_complete
    return future.result()
  File "/Users/yilu/Documents/7k/aaa.py", line 17, in gethtml
    r = await client.get(url)    
  File "/Users/yilu/opt/anaconda3/lib/python3.8/site-packages/httpx/_client.py", line 1722, in get
    return await self.request(
  File "/Users/yilu/opt/anaconda3/lib/python3.8/site-packages/httpx/_client.py", line 1481, in request
    response = await self.send(
  File "/Users/yilu/opt/anaconda3/lib/python3.8/site-packages/httpx/_client.py", line 1568, in send
    response = await self._send_handling_auth(
  File "/Users/yilu/opt/anaconda3/lib/python3.8/site-packages/httpx/_client.py", line 1604, in _send_handling_auth
    response = await self._send_handling_redirects(
  File "/Users/yilu/opt/anaconda3/lib/python3.8/site-packages/httpx/_client.py", line 1640, in _send_handling_redirects
    response = await self._send_single_request(request, timeout)
  File "/Users/yilu/opt/anaconda3/lib/python3.8/site-packages/httpx/_client.py", line 1681, in _send_single_request
    ) = await transport.handle_async_request(
  File "/Users/yilu/opt/anaconda3/lib/python3.8/site-packages/httpx/_transports/default.py", line 283, in handle_async_request
    ) = await self._pool.handle_async_request(
  File "/Users/yilu/opt/anaconda3/lib/python3.8/site-packages/httpcore/_async/http_proxy.py", line 102, in handle_async_request
    await self._keepalive_sweep()
  File "/Users/yilu/opt/anaconda3/lib/python3.8/site-packages/httpcore/_async/connection_pool.py", line 303, in _keepalive_sweep
    now = await self._backend.time()
  File "/Users/yilu/opt/anaconda3/lib/python3.8/site-packages/httpcore/_backends/auto.py", line 64, in time
    return await self.backend.time()
  File "/Users/yilu/opt/anaconda3/lib/python3.8/site-packages/httpcore/_backends/anyio.py", line 198, in time
    return float(anyio.current_time())
TypeError: float() argument must be a string or a number, not 'coroutine'

以前、python 3.7で動かした時は正常でした。しかし、今では、私はそれに対処することはできません。誰か助けてくれませんか?ありがとうございました

4

1 に答える 1