requests 模块和 aiohttp 发送的请求, urlencode 为啥会有这个区别

查看 50|回复 1
作者:ohayoo   
各位大佬,我今天用 requests 模块调接口正常,用 aiohttp 模块调接口出问题,排查发现是 aiohttp 发送请求时的 urlencode 和 requests 的不一样,具体如下,请问下大佬们,这个要如何处理呢?
url = "http://api.baidu.com/test-files/testFiles/1234/%E9%97%AE%E9%A2%98%E5%8D%95%E6%97%B6%E6%95%88-%E8%B7%9F%E8%BF%9B_2020-04-02%2000%3A00%3A00_2020-04-08%2000%3A00%3A00_5675.xlsx.zip"
def delete_url1(url):
    r = requests.delete(url)
    print(f"requests 模块请求地址为:{r.url}")
delete_url1(url)
print()
async def delete_url2(url):
    async with aiohttp.ClientSession() as session:
        async with session.delete(url) as resp:
            print(f"aiohttp 模块请求地址为:{resp.url}")
asyncio.run(delete_url2(url))
执行结果:
requests 模块请求地址为: http://api.baidu.com/test-files/testFiles/1234/%E9%97%AE%E9%A2%98%E5%8D%95%E6%97%B6%E6%95%88-%E8%B7%9F%E8%BF%9B_2020-04-02%2000%3A00%3A00_2020-04-08%2000%3A00%3A00_5675.xlsx.zip
aiohttp 模块请求地址为: http://api.baidu.com/test-files/testFiles/1234/%E9%97%AE%E9%A2%98%E5%8D%95%E6%97%B6%E6%95%88-%E8%B7%9F%E8%BF%9B_2020-04-02%2000:00:00_2020-04-08%2000:00:00_5675.xlsx.zip

url, aiohttp, Requests, 模块

ohayoo
OP
  

您需要登录后才可以回帖 登录 | 立即注册

返回顶部