Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork33.7k
Description
Bug report
asyncio.Protocol.data_received prototype not respected: when usingcreate_connection to create a tcp transportdata_received is being called with abytearray object instead ofbytes.
If this is expected behaviour libraries like httpx and such should be warned or the prototype modified, although I doubt it's intended because it would suppose the generator doesn't hold reference to it otherwise data could change while stored in buffered stuff.
importsysprint(f'Python:{sys.version}\n')importasyncioclassMyProto(asyncio.Protocol):defdata_received(self,data:bytes)->None:print('@@@@@@@@@@ ',data)defeof_received(self):print('##########')asyncdefmain():t,proto=awaitasyncio.get_running_loop().create_connection(MyProto,'example.com',80)t.write(b'SITE BE MAD\n\n')awaitasyncio.sleep(1)t.close()asyncio.run(main())
Correct output:@@@@@@@@@@ b'HTTP/1.0 ...WHATEVER THE SERVER ANSWERS...'
Faulty output:@@@@@@@@@@ bytearray(b'HTTP/1.0 ...WHATEVER THE SERVER ANSWERS...')
Your environment
On Windows 11 x64
Tested on:
- 3.11.0 (main, Oct 24 2022, 18:26:48) [MSC v.1933 64 bit (AMD64)]
- 3.10.1 (tags/v3.10.1:2cd268a, Dec 6 2021, 19:10:37) [MSC v.1929 64 bit (AMD64)]
Working as expected in:
- 3.9.9 (tags/v3.9.9:ccb0e6a, Nov 15 2021, 18:08:50) [MSC v.1929 64 bit (AMD64)]
Related problems
Link to the thread where I found a conflicting thing (it's being solved there as a workaround)
encode/httpx#2305 (comment)
EDIT: simplified the minimal example
Linked PRs
Metadata
Metadata
Assignees
Projects
Status