关于python请求包的问题
所以,我最近开始学习python的请求包,我遇到了一个挑战。 起初,我得到了一个链接“”,它只给了我一个提示:查询参数id必须是UUIDv4 我开始研究这个问题,到目前为止,我已经想到了这个:关于python请求包的问题,python,html,python-requests,Python,Html,Python Requests,所以,我最近开始学习python的请求包,我遇到了一个挑战。 起初,我得到了一个链接“”,它只给了我一个提示:查询参数id必须是UUIDv4 我开始研究这个问题,到目前为止,我已经想到了这个: ''' 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"
'''
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
“”
def get_最佳_频率(nb_of_请求=50):
"""
这将发送一行中的多个请求以引发错误429,并通过设置它来获得“最佳频率”
我们得到的最大“X-速率极限-剩余”误差为+10%
:param nb_of_requests:为引发错误而发送的请求数
:return:在两次请求之间等待的安全时间(毫秒)
:rtype:int
"""
会话=请求。会话()
query=uuid.uuid4()
最佳频率=0
标题={
“用户代理”:“Chrome/79.0.3945.88”,
}
对于范围内的i(n个请求中的n个):
response=session.get(“http://pms.zelros.com,params={'id':查询},headers=headers)
如果response.headers.get('X-Rate-Limit-Remaining')不是None且int(response.headers.get('X-Rate-Limit-Remaining'))>最佳_频率:
最佳_频率=int(response.headers.get('X-Rate-Limit-Remaining'))
返回1.1*最佳_频率
def spam_直到_分数(分数):
"""
这将使用uuidv4发送请求,直到达到所需分数
:param score:需要的分数
:return:最后一个请求的响应
:rtype:requests.models.Response
"""
开始=时间。时间()
当前分数=0
query=uuid.uuid4()
会话=请求。会话()
最佳频率=获取最佳频率()
标题={
“用户代理”:“Chrome/79.0.3945.88”,
}
而(当前分数<分数):
response=session.get(“http://pms.zelros.com,params={'id':查询},headers=headers)
dict_response=response.json()
如果(int(dict_response.get('score'))
但我被卡住了,目标是达到100万分,而达到10000分需要5536秒
到目前为止,我得到的帮助如下:
10000级
来自/人
让我们添加一个人员负载
“人”:[x,x,x]
2000级
您可以添加分数有效负载以优化您的准备
700级
你可以/准备你的请求
300级
好的开始。很简单:)
让我们使用一些奇特的http动词
100级
你已经知道你不能给我发垃圾邮件
但是你知道有一个最佳的联系频率吗
级别0
你好!
欢迎来到泽罗斯挑战赛
目标是达到一百万分
很抱歉发了这么长的信息,但我有以下问题:
-有没有一种方法可以发送更多请求而不引发错误429,或者使用并行请求?如果是,我应该怎么做?
-我真的不明白准备请求对我有什么帮助。
-除了GET之外,我还可以使用哪些html方法
谢谢你的时间和帮助