Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/actionscript-3/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Github api Github 304响应似乎不符合速率限制_Github Api_Rate Limiting - Fatal编程技术网

Github api Github 304响应似乎不符合速率限制

Github api Github 304响应似乎不符合速率限制,github-api,rate-limiting,Github Api,Rate Limiting,我遇到了一个github api计数请求的问题,该请求根据速率限制生成304响应 GET /repos/******/***/contents/***?ref=master HTTP/1.1 Host: api.github.com Connection: keep-alive Cache-Control: max-age=0 Sec-Fetch-Dest: empty If-None-Match: W/"b15846765021dc2483e5f3110b53a69f210ececa

我遇到了一个github api计数请求的问题,该请求根据速率限制生成304响应

GET /repos/******/***/contents/***?ref=master HTTP/1.1
Host: api.github.com
Connection: keep-alive
Cache-Control: max-age=0
Sec-Fetch-Dest: empty
If-None-Match: W/"b15846765021dc2483e5f3110b53a69f210ececa"
If-Modified-Since: Thu, 19 Mar 2020 01:33:51 GMT
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.149 Safari/537.36
Accept: */*
Origin: *******
Sec-Fetch-Site: cross-site
Sec-Fetch-Mode: cors
Referer: ******
Accept-Encoding: gzip, deflate, br
Accept-Language: en-US,en;q=0.9
此请求将返回304,无正文,但X-Ratelimit剩余递减

注意:发出有条件的请求并收到304响应不计入您的费率限制,因此我们鼓励您尽可能使用它

我只设置If None Match,如果自头被修改,其余的由浏览器设置(使用fetchapi)

要求 通过导航到
https://api.github.com/repos/angular/angular/contents/?ref=master
并确保在开发人员控制台中禁用缓存

响应 第一次通话
如果不匹配
如果修改,因为未设置

HTTP/1.1 200 OK
date: Wed, 01 Apr 2020 12:43:09 GMT
content-type: application/json; charset=utf-8
server: GitHub.com
status: 200 OK
cache-control: public, max-age=60, s-maxage=60
vary: Accept, Accept-Encoding, Accept, X-Requested-With
etag: W/"b15846765021dc2483e5f3110b53a69f210ececa"
last-modified: Thu, 19 Mar 2020 01:33:51 GMT
x-github-media-type: github.v3; format=json
access-control-expose-headers: ETag, Link, Location, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type, Deprecation, Sunset
access-control-allow-origin: *
strict-transport-security: max-age=31536000; includeSubdomains; preload
x-frame-options: deny
x-content-type-options: nosniff
x-xss-protection: 1; mode=block
referrer-policy: origin-when-cross-origin, strict-origin-when-cross-origin
content-security-policy: default-src 'none'
content-encoding: gzip
X-Ratelimit-Limit: 60
X-Ratelimit-Remaining: 59
X-Ratelimit-Reset: 1585748589
Accept-Ranges: bytes
Content-Length: 1696
X-GitHub-Request-Id: B298:74D9:10D7B8:177665:5E848C5D

然后是请求的数据

后续电话:
If None Match
If Modified Since
被设置为
etag
上次修改的
来自上一个请求的标题

HTTP/1.1 304 Not Modified
date: Wed, 01 Apr 2020 12:44:51 GMT
content-type: application/json; charset=utf-8
server: GitHub.com
status: 200 OK
cache-control: public, max-age=60, s-maxage=60
vary: Accept, Accept-Encoding, Accept, X-Requested-With
etag: W/"b15846765021dc2483e5f3110b53a69f210ececa"
last-modified: Thu, 19 Mar 2020 01:33:51 GMT
x-github-media-type: github.v3; format=json
access-control-expose-headers: ETag, Link, Location, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type, Deprecation, Sunset
access-control-allow-origin: *
strict-transport-security: max-age=31536000; includeSubdomains; preload
x-frame-options: deny
x-content-type-options: nosniff
x-xss-protection: 1; mode=block
referrer-policy: origin-when-cross-origin, strict-origin-when-cross-origin
content-security-policy: default-src 'none'
content-encoding: gzip
X-Ratelimit-Limit: 60
X-Ratelimit-Remaining: 58
X-Ratelimit-Reset: 1585748589
X-GitHub-Request-Id: FC10:2036:26E528:346432:5E848CC3

没有返回任何数据。 根据文件
X-rate limit-Remaining
应保持在59

我的请求有什么问题吗?或者是GitEnd上的ratelimit有问题吗

根据文件
X-rate limit-Remaining
应保持在59

此处的
59
表明您正在执行未经验证的请求,这可能是此处的关键。我想知道这是否与未经验证的请求的速率限制有关,未经验证的请求的度量方式与经验证的请求的度量方式不同,并且这种情况可能不被视为“有条件”请求


这种情况没有明确记录,但GitHub强烈建议使用经过身份验证的请求,因为这些速率限制是按帐户跟踪的,而不是按IP地址跟踪的。

也遇到了同样的问题。并解决了这个问题。我已将带有字符串值的“授权”键添加到标题中。我正在使用python和针对人类的请求。因此,在我的控制台中如下所示:

>>> response = requests.get('http://api.github.com/repos/zappycode/zappycode-django/commits', headers={'Authorization': 'JustaString', 'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64; rv:79.0) Gecko/20100101 Firefox/79.0', 'If-Modified-Since': 'Sat, 18 Jul 2020 00:15:14 GMT'})
>>> response.headers
{'Date': 'Tue, 21 Jul 2020 09:06:05 GMT', 'Server': 'GitHub.com', 'Status': '304 Not Modified', 'X-RateLimit-Limit': '60', 'X-RateLimit-Remaining': '59', 'X-RateLimit-Reset': '1595323695', 'Cache-Control': 'public, max-age=60, s-maxage=60', 'Vary': 'Accept, Accept-Encoding, Accept, X-Requested-With, Accept-Encoding', 'ETag': '"03e2ffed23748e4e7fee925076e63b47"', 'Last-Modified': 'Sat, 18 Jul 2020 00:15:14 GMT', 'Access-Control-Expose-Headers': 'ETag, Link, Location, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type, Deprecation, Sunset', 'Access-Control-Allow-Origin': '*', 'Strict-Transport-Security': 'max-age=31536000; includeSubdomains; preload', 'X-Frame-Options': 'deny', 'X-Content-Type-Options': 'nosniff', 'X-XSS-Protection': '1; mode=block', 'Referrer-Policy': 'origin-when-cross-origin, strict-origin-when-cross-origin', 'Content-Security-Policy': "default-src 'none'", 'X-GitHub-Request-Id': 'B6AC:EC41:82A5D:B3030:5F16AFFD'}
>>> response_2 = requests.get('http://api.github.com/repos/zappycode/zappycode-django/commits', headers={'Authorization': 'JustaString', 'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64; rv:79.0) Gecko/20100101 Firefox/79.0', 'If-Modified-Since': 'Sat, 18 Jul 2020 00:15:14 GMT'})
>>> response_2.headers
{'Date': 'Tue, 21 Jul 2020 09:06:44 GMT', 'Server': 'GitHub.com', 'Status': '304 Not Modified', 'X-RateLimit-Limit': '60', 'X-RateLimit-Remaining': '59', 'X-RateLimit-Reset': '1595323695', 'Cache-Control': 'public, max-age=60, s-maxage=60', 'Vary': 'Accept, Accept-Encoding, Accept, X-Requested-With, Accept-Encoding', 'ETag': '"03e2ffed23748e4e7fee925076e63b47"', 'Last-Modified': 'Sat, 18 Jul 2020 00:15:14 GMT', 'Access-Control-Expose-Headers': 'ETag, Link, Location, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type, Deprecation, Sunset', 'Access-Control-Allow-Origin': '*', 'Strict-Transport-Security': 'max-age=31536000; includeSubdomains; preload', 'X-Frame-Options': 'deny', 'X-Content-Type-Options': 'nosniff', 'X-XSS-Protection': '1; mode=block', 'Referrer-Policy': 'origin-when-cross-origin, strict-origin-when-cross-origin', 'Content-Security-Policy': "default-src 'none'", 'X-GitHub-Request-Id': 'A962:EC4D:11CCB9AF:15D06EA5:5F16B023'}
>>> response_3 = requests.get('http://api.github.com/repos/zappycode/zappycode-django/commits', headers={'Authorization': 'JustaString', 'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64; rv:79.0) Gecko/20100101 Firefox/79.0', 'If-Modified-Since': 'Sat, 18 Jul 2020 00:15:14 GMT'})
>>> response_3.headers
{'Date': 'Tue, 21 Jul 2020 09:07:39 GMT', 'Server': 'GitHub.com', 'Status': '304 Not Modified', 'X-RateLimit-Limit': '60', 'X-RateLimit-Remaining': '59', 'X-RateLimit-Reset': '1595323695', 'Cache-Control': 'public, max-age=60, s-maxage=60', 'Vary': 'Accept, Accept-Encoding, Accept, X-Requested-With, Accept-Encoding', 'ETag': '"03e2ffed23748e4e7fee925076e63b47"', 'Last-Modified': 'Sat, 18 Jul 2020 00:15:14 GMT', 'Access-Control-Expose-Headers': 'ETag, Link, Location, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type, Deprecation, Sunset', 'Access-Control-Allow-Origin': '*', 'Strict-Transport-Security': 'max-age=31536000; includeSubdomains; preload', 'X-Frame-Options': 'deny', 'X-Content-Type-Options': 'nosniff', 'X-XSS-Protection': '1; mode=block', 'Referrer-Policy': 'origin-when-cross-origin, strict-origin-when-cross-origin', 'Content-Security-Policy': "default-src 'none'", 'X-GitHub-Request-Id': 'A968:69B0:11A84908:159BBA46:5F16B05B'}

希望对你有用:)

你能分享你看到的回复标题吗?其中可能有一些细节,有助于更好地理解行为。此外,也许在这里去掉一些不必要的标题,而只保留一些必要的标题可能会有所帮助。据我所知,唯一的基本标题是
如果不匹配
如果修改,因为
您是正确的,请求未经验证。很可能是没有auth,条件请求就无法工作。但在任何地方都找不到记录