开发者

Get Request Using PyCurl after logging into website

开发者 https://www.devze.com 2023-01-06 22:54 出处:网络
After doing a post to log into my website, I try to do a get on my the site and I get a bunch of garbage开发者_C百科\"�0������`&)��붋....\" instead of the data from my site. Why is that?

After doing a post to log into my website, I try to do a get on my the site and I get a bunch of garbage开发者_C百科 "�0������`&)��붋...." instead of the data from my site. Why is that? How do I fix that?


Obviously a dead thread, but if anyone else stumbles across this, funky data like that is most likely compressed with zlib or gzip. If you are using pycurl, this should do the trick:

import pycurl

ch = pycurl.Curl()
ch.setopt(pycurl.URL, 'http://example.com')
ch.setopt(pycurl.ENCODING, '')
ch.perform()

Setting the ENCODING option to an empty string sets the 'Accept-Encoding' headers to all encodings supported by libcurl and tells libcurl to decode the response data. OP was probably setting the headers manually and libcurl wasn't expecting encoded data.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号