4

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?

StasEvseev
  • 95
  • 8

2 Answers2

7

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.

Daniel Stenberg
  • 54,736
  • 17
  • 146
  • 222
1

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

EI7DKB
  • 11
  • 1