这是我的网址:https://10.10.10.20/v1/device[]=1_2234。
当我在 Python 脚本中发送 URL 时,它会将 [] 替换为 %5B 和 %5D。
import requests
url = 'https://10.10.10.20/v1/device[]=1_2234'
response = requests.get(api_key, url)
print(response)
错误:
requests.exceptions.HTTPError: 404 Client Error: Not Found for url: https://10.10.10.20/v1/device%5B%5D=1_2234
尝试在每个括号前使用反斜杠转义括号
url = 'https://10.10.10.20/v1/device\[\]=1_2234'
您还可以通过在字符串之前放置 r 来使用原始字符串
url = r'https://10.10.10.20/v1/device[]=1_2234'