StasEvseev
StasEvseev

Reputation: 105

How make HEAD request to pycurl

I need to send a HTTP HEAD request using pycurl.

This code

curl = pycurl.Curl()
...
curl.setopt(curl.CUSTOMREQUEST, "HEAD")
curl.perform()

produces an error:

< HTTP/1.1 200 OK
* Server nginx/1.6.2 is not blacklisted
< Server: nginx/1.6.2
< Date: # No matters
< Content-Type: text/html; charset=utf-8
< Connection: keep-alive
< Cache-Control: no-cache,no-store,must-revalidate
< Pragma: no-cache
< Expires: # No matters
< Last-Modified: # No matters
< Content-Security-Policy: # No matters
< X-Frame-Options: SAMEORIGIN
< X-XSS-Protection: # No matters
< X-Content-Type-Options: nosniff
< Content-Encoding: gzip
* no chunk, no close, no size. Assume close to signal end
< 
* Operation timed out after 15001 milliseconds with 0 bytes received
* Closing connection 1

Can anybody help me?

Upvotes: 4

Views: 1958

Answers (2)

EI7DKB
EI7DKB

Reputation: 11

Just to clarify. You don't need to make a CUSTOMREQUEST! Merely specifying a 'NOBODY' option is sufficient for pycurl to generate a 'HEAD' request itself. Tested with PycURL/7.43.0 libcurl/7.51.0

Upvotes: 1

Daniel Stenberg
Daniel Stenberg

Reputation: 58034

You want the NOBODY option. As in no body please. Just changing the CUSTOMREQUEST does not make libcurl change how it behaves and it will think it does a GET but you change it to a HEAD and then things will go bad.

Upvotes: 7

Related Questions