How to fix 'TypeError: argument of type 'URL' is not iterable' when trying to look for values in a url with aiohttp

How to fix 'TypeError: argument of type 'URL' is not iterable' when trying to look for values in a url with aiohttp

当使用 AIOHTTP 并返回请求的 url 时,我试图迭代并在 url 中查找某些值。如果有某个值,它必须对 url.

做一些事情

我已经尝试使用 for 循环解析 requrl.url,但这也不起作用。当我将 requrl.url 附加到列表时,它会像这样附加 link:[URL('https://twitter.com/home')]

async with session.get(https://twitter.com/) as requrl:
    print (requrl.url)

    if 'home' in requrl.url:
        #do something

如果homerequrl.url中,预期结果显然满足条件,但是通过这段代码执行时,条件不满足。

给出的错误是TypeError: argument of type 'URL' is not iterable

同样,如果我将 requrl.url 附加到列表中,列表将显示为 [URL('https://twitter.com/home')]

我假设因为 URL 部分是上面的列表,当解析它时找不到它的值。

感谢任何帮助!

已解决。必须将值更改为字符串。

async with session.get(https://twitter.com/) as requrl:
    print (requrl.url)

    if 'home' in str(requrl.url):
        #do something