私はPythonには新しく、ライブラリを使用しようとしています。それは例外を発生させ、私はそれを特定しようとしています。これは私がしようとしているものです:tweepy例外インスタンスからエラーコードを取得
except tweepy.TweepError as e:
print e
print type(e)
print e.__dict__
print e.reason
print type(e.reason)
これは私が取得していますものです:
[{u'message': u'Sorry, that page does not exist', u'code': 34}]
<class 'tweepy.error.TweepError'>
{'reason': u"[{u'message': u'Sorry, that page does not exist', u'code': 34}]", 'response': <httplib.HTTPResponse instance at 0x00000000029CEAC8>}
[{u'message': u'Sorry, that page does not exist', u'code': 34}]
<type 'unicode'>
イムをそのコードを取得しようとしています。 e.reason.codeを成功させようとしましたが、何を試していいのかわかりません。
ええ - 私はそれを誤読したかもしれません - 'e.reason [0] ['code']'はどうでしょうか? –
トレースバック(最新の呼び出しの最後): 印刷e.reasonで ファイル "descargar.py"、ライン70、[0] [ 'コード'] はTypeError:文字列のインデックスは整数 –
@alecxeでなければなりません申し訳ありませんが、これはでしたいくつかの時間前に、私は何をしたのか覚えていないが、私はコードを(私が望むように)得た。それにもかかわらず、あなたの答えは働くので、私はそれを受け入れます:) –