向GET请求时
https://apicache.vudu.com/api2/?_type=contentSearch&contentEncoding=gzip&contentId={}&dimensionality=any&followup=ultraVioletability&followup=longCredits&followup=superType&followup=episodeNumberInSeason&followup=advertContentDefinitions&followup=tag&followup=hasBonusWithTagExtras&followup=subtitleTrack&followup=ratingsSummaries&followup=geneGenres&followup=seasonNumber&followup=trailerEditionId&followup=genres&followup=usefulStreamableOffers&followup=walmartOffers&followup=preOrderOffers&followup=editions&followup=merchandiseContentMaps&followup=promoTags&followup=advertEnabled&format=application%2Fjson
从AWS ,我间歇性地收到以下错误:
ContentDecodingError: ('Received response with content-encoding: gzip, but failed to decode it.', error('Error -3 while decompressing: incorrect header check',))
示例:
requests.get(url.format('832504'))
<Response [200]>
requests.get(url.format('460398'))
<Response [200]>
requests.get(url.format('27616'))
<Response [200]>
requests.get(url.format('23657'))
<Response [200]>
requests.get(url.format('8661'))
ContentDecodingError...
requests.get(url.format('14250'))
<Response [200]>
requests.get(url.format('516307'))
ContentDecodingError...
requests.get(url.format('10366'))
<Response [200]>
我尝试了不同的标头组合(包括此处的建议:https://github.com/requests/requests/issues/3849)并删除了contentEncoding=gzip
参数(返回502状态代码)。
考虑到该API在我的PC上可以正常使用,也许Vudu和AWS之间存在一些冲突?
答案 0 :(得分:0)
我认为这是当前的python请求库限制(或设计行为,请参见here)
因此,您必须使用resp.raw
来获取原始字节。 (注意:要访问resp.raw
,还需要stream=True
)。
resp = session.get(url, stream=True)
data = resp.raw.read()