πŸ‘©πŸ»‍πŸ’»/python

[python] Received response with content-encoding: gzip, but failed to decode it.

바쿄리 2024. 2. 19. 14:53

 

μ—λŸ¬ : Received response with content-encoding: gzip, but failed to decode it.', error('Error -3 while decompressing data: incorrect data check')

res = requests.get( page_url, headers={ 'User-Agent': utils.get_random_agent() }, timeout=10 )
content = res.content

 

 

μœ„μ™€ 같이 μš”μ²­μ‹œ, μ•„λž˜μ™€ 같은 메세지와 ν•¨κ»˜ 크둀링이 진행이 λΆˆκ°€ν•œ 상황이 λ°œμƒν–ˆλ‹€.

# error
Received response with content-encoding: gzip, but failed to decode it.', error('Error -3 while decompressing data: incorrect data check')

 

μ˜΅μ…˜μ„ μΆ”κ°€ν–ˆλ‹€.

res = requests.get( page_url, headers={ 'User-Agent': utils.get_random_agent(), 'Accept-Encoding': 'identity' }, timeout=10, stream=True )
content = res.raw.read()

 

* μΆ”κ°€λœ 것은

1. 'Accept-Encoding': 'identity'

2. stream=True

 

* μˆ˜μ •λœ 것은

content = res.content 으둜 κ°€μ§€κ³  μ˜€λŠ” 것 λŒ€μ‹  content = res.raw.read() 으둜 μ½μ–΄μ£Όλ‹ˆ 잘 μ§„ν–‰λ˜λŠ” 것을 ν™•μΈν–ˆλ‹€.

근데 μ’€ 느렀짐