python - 在发布 API 之前休眠 X 秒 - Python
问题描述
我需要在网站上发布一些记录。我觉得我已经完成了复杂的部分 - 代码本身,现在我需要调整代码,以便我的帐户在发布时不会被阻止 - 是的,只是发生了。
#importing libraries
import csv
import json
#changing data type
field_types = [('subject', str),
('description', str),
('email', str)]
output = []
#opening the raw file
with open('file.csv','r',encoding = 'utf-8-sig') as f:
for row in csv.DictReader(f):
row.update((key, conversion(row[key]))
for key, conversion in field_types)
output.append(row) #appending rows
with open('tickets.json','w') as outfile: #saving records as json
json.dump(output,outfile,sort_keys = True, indent = 4)
with open('tickets.json','r')as infile:
indata = json.load(infile)
output =[]
for data in indata:
r= requests.post("https://"+ domain +".domain.com/api/", auth = (api_key, password), headers = headers, json=data)
output.append(json.loads(r.text))
#saving the response code
with open('response.json', 'w') as outfile:
json.dump(output, outfile, indent = 4)
我搜索并找到了 time.sleep(5) 但现在知道如何使用它了。会先过去output.append(json.loads(r.text))
吗?
解决方案
推荐阅读
- c++ - 从 http 流(在 boost::beast 中)读取和写入的要求是什么?
- python - 如何在 Python 中使用 matplotlib 绘制数据?
- dimensional-modeling - DM 和层次结构 - 未来使用的维度
- python-3.x - ls -l 的打印输出 | 奇怪的东西
- c++ - 如何使用 CMake 使混合 C/C++ 项目工作
- angular - 使用条纹支付按钮时无法关闭角度材质对话框
- java - java.lang.ClassCastException:java.util.LinkedHashMap 无法转换为 com.mx.model.usermgmt.UserDetails
- c++ - 面向对象编程 - 位域私有结构的公共参考
- python-3.x - 在 Python 中的列表中创建连续项目的矩阵
- r - R:从向量中复制某些元素并将它们粘贴到数据框中