python - 关于python requests 包的问题
问题描述
所以,我最近开始学习 python 的 requests 包,我遇到了一个挑战。起初我得到了一个链接“<a href="http://pms.zelros.com/" rel="nofollow noreferrer">http://pms.zelros.com/”,它只给了我一个提示:查询参数 id 必须是 uuid v4
我开始研究这个,到目前为止我想出了这个:
'''
def get_optimal_frequency(nb_of_requests=50):
"""
This sends a number of request in a row to raise Error 429 and get the "optimal frequency" by setting it
to the maximal 'X-Rate-Limit-Remaining' that we got + 10% as a margin of error
:param nb_of_requests: The number of requests sent to raise the Error
:return: The safe time to wait between requets in ms
:rtype: int
"""
session = requests.Session()
query = uuid.uuid4()
optimal_frequency = 0
headers = {
'User-Agent': 'Chrome/79.0.3945.88',
}
for i in range(nb_of_requests):
response = session.get("http://pms.zelros.com", params={'id':query}, headers=headers)
if response.headers.get('X-Rate-Limit-Remaining') is not None and int(response.headers.get('X-Rate-Limit-Remaining')) > optimal_frequency:
optimal_frequency = int(response.headers.get('X-Rate-Limit-Remaining'))
return 1.1*optimal_frequency
def spam_until_score(score):
"""
This sends requests with a uuidv4 until the desired score is reached
:param score: The score wanted
:return: The response of the last request
:rtype: requests.models.Response
"""
start = time.time()
current_score = 0
query = uuid.uuid4()
session = requests.Session()
optimal_frequency = get_optimal_frequency()
headers = {
'User-Agent': 'Chrome/79.0.3945.88',
}
while(current_score < score):
response = session.get("http://pms.zelros.com", params={'id':query}, headers=headers)
dict_response = response.json()
if (int(dict_response.get('score')) < current_score):
break
else:
current_score = int(dict_response.get('score'))
time.sleep(optimal_frequency/1000)
end = time.time()
duration = end - start
return response, duration
但我被困住了,目标是达到 1 000 000 分,而达到 10 000 分需要 5536 秒。
到目前为止,我得到的帮助是:
10000级
来自/人
让我们添加一个人员有效载荷
“人”:[x,x,x]
2000级
您可以添加分数有效负载以优化您的准备工作
700级
您可以/准备您的请求。
300级
好的开始。很容易 :)
让我们使用一些花哨的 http 动词。
100级
你已经知道你不能向我发送垃圾邮件。
但是您知道与我联系的最佳频率吗?
0级
你好 !
欢迎来到 Zelros 挑战
目标是达到一百万分。
对不起,很长的信息,但这是我的问题:
- 有没有办法在不引发错误 429 的情况下发送更多请求,也许使用并行请求?如果是,我该怎么做?-我真的不明白准备请求对我有什么帮助。- 除了 GET 之外,我还可以使用哪些其他 html 方法?
感谢您的时间和帮助
解决方案
推荐阅读
- amazon-web-services - 添加 EIP 后 EC2 公共 IPv4 变得无法访问
- laravel - Laravel:无法上传视频和图像文件
- java - 如何从没有实例名称的 main 中的另一个类调用 void 方法?
- google-cloud-platform - Informatica byol /IICS vs google data flow /data proc 需要的利弊
- vue.js - 如何使用 Nuxt 组件将参数传递给 vuex getter 方法?(同时保持三点符号)
- javascript - Flutter Google Cloud Functions 获取 Firestore 触发器的 UID
- database - 如何设计一个用户可以自定义一些配置的系统后端
- c - 如何在按钮单击 GTK c 时更改多个小部件属性
- sqlalchemy - 在具有 3 个表的数据库中使用 SQLAlchemy 创建嵌套连接
- reactjs - 如何让 require(packagename) 工作,错误:无法在反应中解析 'api/DefaultApi'