python - Use API to write to json file
问题描述
I am facing this problem while I try to loop tweet_id
using the API and write it to tweet_json.txt
, the output for all data is Failed
which I know is wrong
Before it was working good but when I try to Run all the code again it starts to show failed
for tweet_id in df['tweet_id']:
try:
tweet = api.get_status(tweet_id, tweet_mode = 'extended')
with open('tweet_json.txt', 'a+') as file:
json.dump(tweet._json, file)
file.write('\n')
print (tweet_id, 'success')
except:
print (tweet_id, 'Failed')
解决方案
Your except
is swallowing whatever exception is causing your code to die. Until you comment out the except
or make it more specific you won't know if your problem is the Twitter API or file I/O or something else. Good luck!
推荐阅读
- c - Microsoft Compiler C Program - 请帮助在编译期间使用 _Pragma 消息将宏参数(它是一个字符串)打印到构建日志
- sql - 如何使用 REGEXP_SUBSTR() 从 oracle 中的表中提取字符串的某些部分(条件不包括第一个空格的前面部分)
- python - while循环中的pop变量在完成后不会打印
- c# - 在 C# 中的 datagridview 中计算重复值和求和值
- python - 用python计算分歧
- debugging - 为什么通过int 0x80调用exit后程序继续运行?
- xamarin - Xamarin.Forms - 如何动态更改 CarouselView 的高度?
- c++ - 来自 PCL 点云的 2D 边界框
- java - Cannot resolve method 'setText(java.lang.String[] with ResultView
- sharepoint - 为什么我的 nintex 上的复选框在第一次用户选择后不接受响应?