私はそれが大いに文書化されていることを知っていて、私はそれが行くべきだと思うどこでも.read().decode('utf-8')
を配置しようとしましたが、私はまだ何かが不足しています。私はPython 2.7でオブジェクトIDをフェッチすることでデータのESRI REST URLをスクラップするスクリプトを作成しました。しかし、Python 3では協調しているようには見えません。それは29行目で失敗し続けます(下記参照)。どんな助けでも大いに感謝します。Python 3 Urlopenの問題
version = json.loads(webresp.decode('utf-8'))['currentVersion']
私は常に一貫してこのエラーを取得しています:
Traceback (most recent call last):
File "<pyshell#20>", line 1, in <module>
main(url, jsonfilelocation, jsonfilename)
File "\\SERVER\Projects\Python\TOUCH\esrirestjson.py", line 73, in main
oids = ESRIJSON().getobjrange(webconn, path)
File "\\SERVER\Projects\Python\TOUCH\esrirestjson.py", line 29, in getobjrange
version = json.loads(webresp.decode('utf-8'))['currentVersion']
File "C:\ArcGISPro\bin\Python\envs\arcgispro-py3\lib\json\__init__.py", line 312, in loads
s.__class__.__name__))
TypeError: the JSON object must be str, not 'bytes'
「ESRIJSON」クラスを実際にインスタンス化した例のコードを追加できますか?私は間違いなく答えを提供し、コードを自分ですぐにテストすることができます。ありがとう – jamescampbell
あなたのエラーはここにあります:** version = json.loads(webresp.decode( 'utf-8'))['currentVersion'] **何を試しましたか? - なぜこのコード全体を投稿する必要がありますか? –
https://stackoverflow.com/questions/31708519/request-returns-bytes-and-im-failing-to-decode-themおそらく.contentを追加しようとしますか? webconn.getresponse()。content –