Python 为什么在get请求中出现以下错误
我有这样的代码:Python 为什么在get请求中出现以下错误,python,string,http,get,python-requests,Python,String,Http,Get,Python Requests,我有这样的代码: import requests import xmltodict Locations = ['http://129.94.5.93:49154/setup.xml', 'http://129.94.5.92:49154/setup.xml', 'http://129.94.5.93:49154/setup.xml', 'http://129.94.5.92:49154/setup.xml', 'http://129.94.5.95:80/description.xml']
import requests
import xmltodict
Locations = ['http://129.94.5.93:49154/setup.xml', 'http://129.94.5.92:49154/setup.xml', 'http://129.94.5.93:49154/setup.xml', 'http://129.94.5.92:49154/setup.xml', 'http://129.94.5.95:80/description.xml']
for item in Locations:
r = requests.get(item)
reply = xmltodict.parse(r.text)
这给了我以下错误:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "ssdpxml.py", line 57, in <module>
r = requests.get(item)
AttributeError: 'str' object has no attribute 'get'
为什么会出现上述错误???请检查您是否真的导入了
请求
,并且没有对该模块进行阴影处理。很抱歉,意外按下了删除按钮。。。但是是的,我正在导入请求。。。一个影子是怎样形成的module@sikhvir请尝试导入请求
,然后尝试打印请求。_文件_
或打印请求。_路径_
。或者打印目录(请求)
显示该模块的功能等的内容。如果它们与您期望的不同,实际上您导入了不同的内容,\uuuu文件\uuuu
可以告诉您从何处导入。这是隐藏-另一个模块在起作用,您导入它,它隐藏了对您要导入的模块的访问。@sukhvir,听起来您可能定义了一个名为requests
的本地字符串变量,它正在隐藏您导入的模块,就像其他评论员建议的那样。@Addison就是它。。我现在要去岩石下爬
r=requests.get('http://129.94.5.95:80/description.xml')