Python 'str' - Objekt hat kein Attribut 'gelesen'
Python 3.3.2 import json & das urllib.Anfrage
Json
[{"link":"www.google.com","orderid":"100000222"},
{"link":"www.google.com","orderid":"100000222"},
{"link":"www.google.com","orderid":"100000222"}]
print(response.info())
Date: Sun, 20 Oct 2013 07:06:51 GMT
Server: Apache
X-Powered-By: PHP/5.4.12
Content-Length: 145
Connection: close
Content-Type: application/json
Codes
url = "http://www.Link.com"
request = urllib.request.Request(url)
request.add_header('User-Agent','Mozilla/4.0 (compatible; MSIE 5.5; Windows NT)')
request.add_header('Content-Type','application/json')
response = urllib.request.urlopen(request)
decodedRes = response.read().decode('utf-8')
json_object = json.load(decodedRes)
Folgende sind meine codes
Fehler
Traceback (most recent call last):
File "C:\Users\Jonathan\Desktop\python.py", line 57, in <module>
checkLink()
File "C:\Users\Jonathan\Desktop\python.py", line 50, in checkLink
json_object = json.load(decodedRes)
File "C:\Python33\lib\json\__init__.py", line 271, in load
return loads(fp.read(),
AttributeError: 'str' object has no attribute 'read'
>>> .
Irgendeine Idee, wie ich dieses Problem beheben können?
Du musst angemeldet sein, um einen Kommentar abzugeben.
Verwenden
json.Lasten
stattjson.load
.json.Last
akzeptieren Datei-ähnliches Objekt.Alternativ können Sie pass-response-Objekt zu
json.load
:Versuchen, anstelle der
json.load()
mitjson.loads()
. Der ehemalige Bedürfnisse ein Datei-stream-das ist der Grund, warum Sie in der Attribut-Fehler.Es ist sehr einfach, Sie brauchen nur zu importieren schönen Suppe auf eine andere Weise.
Jetzt sind Sie Import als
Ändern