前提・実現したいこと
素人質問失礼します。
PythonでTweepyを使ってアカウント名からユーザIDを取得したのち、同内容のDMを送りたいです。
発生している問題・エラーメッセージ
Traceback (most recent call last): File "C:\Users\81809\AppData\Local\Packages\PythonSoython39\site-packages\tweepy\binder.py", line 184, in resp = self.session.request(self.method, File "C:\Users\81809\AppData\Local\Packages\PythonSoython39\site-packages\requests\sessions.py", line 528, prep = self.prepare_request(req) File "C:\Users\81809\AppData\Local\Packages\PythonSoython39\site-packages\requests\sessions.py", line 456, p.prepare( File "C:\Users\81809\AppData\Local\Packages\PythonSoython39\site-packages\requests\models.py", line 319, i self.prepare_body(data, files, json) File "C:\Users\81809\AppData\Local\Packages\PythonSoython39\site-packages\requests\models.py", line 469, i body = complexjson.dumps(json) File "C:\Program Files\WindowsApps\PythonSoftwareFou", line 231, in dumps return _default_encoder.encode(obj) File "C:\Program Files\WindowsApps\PythonSoftwareFou, line 199, in encode chunks = self.iterencode(o, _one_shot=True) File "C:\Program Files\WindowsApps\PythonSoftwareFou, line 257, in iterencode return _iterencode(o, 0) File "C:\Program Files\WindowsApps\PythonSoftwareFou, line 179, in default raise TypeError(f'Object of type {o.__class__.__na TypeError: Object of type User is not JSON serializabl During handling of the above exception, another except Traceback (most recent call last): File "C:\python\test.py", line 24, in <module> api.send_direct_message(recipient_id=id,text="テス File "C:\Users\81809\AppData\Local\Packages\PythonSoython39\site-packages\tweepy\api.py", line 468, in sen return self._send_direct_message(json_payload=json File "C:\Users\81809\AppData\Local\Packages\PythonSoython39\site-packages\tweepy\binder.py", line 253, in return method.execute() File "C:\Users\81809\AppData\Local\Packages\PythonSoython39\site-packages\tweepy\binder.py", line 192, in six.reraise(TweepError, TweepError('Failed to send File "C:\Users\81809\AppData\Local\Packages\PythonSoython39\site-packages\six.py", line 718, in reraise raise value.with_traceback(tb) File "C:\Users\81809\AppData\Local\Packages\PythonSoython39\site-packages\tweepy\binder.py", line 184, in resp = self.session.request(self.method, File "C:\Users\81809\AppData\Local\Packages\PythonSoython39\site-packages\requests\sessions.py", line 528, prep = self.prepare_request(req) File "C:\Users\81809\AppData\Local\Packages\PythonSoython39\site-packages\requests\sessions.py", line 456, p.prepare( File "C:\Users\81809\AppData\Local\Packages\PythonSoython39\site-packages\requests\models.py", line 319, i self.prepare_body(data, files, json) File "C:\Users\81809\AppData\Local\Packages\PythonSoython39\site-packages\requests\models.py", line 469, i body = complexjson.dumps(json) File "C:\Program Files\WindowsApps\PythonSoftwareFou", line 231, in dumps File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.9_3.9.1520.0_x64__qbz5n2kfra8p0\lib\json\encoder.py", line 257, in iterencode return _iterencode(o, 0) File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.9_3.9.1520.0_x64__qbz5n2kfra8p0\lib\json\encoder.py", line 179, in default raise TypeError(f'Object of type {o.__class__.__name__} ' tweepy.error.TweepError: Failed to send request: Object of type User is not JSON serializable PS C:\python>
該当のソースコード
python
1from re import A 2import tweepy 3 4 5CK= **** 6CS = **** 7AT = **** 8ATS= **** 9 10 11auth=tweepy.OAuthHandler(CK, CS) 12auth.set_access_token(AT, ATS) 13 14 15api = tweepy.API(auth) 16 17 18Account = ["***","***",...,"***"] 19counter=0 20 21while counter<len(Account): 22 id = api.lookup_users(screen_names=Account[counter]) 23 api.send_direct_message(recipient_id=id,text="テスト送信です。") 24 print(Account[counter]) 25 print(id) 26 counter+=1 27 28
試したこと
補足情報(FW/ツールのバージョンなど)
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。