CURLOPT_REQUEST_TARGET with pycurl

74 Views Asked by At

I would like to use pycurl with the option that matches --request-target on the command line tool.

When trying this with the following code:

import pycurl
c = pycurl.Curl()
c.setopt(c.URL, "http://192.168.2.230")
c.setopt(c.REQUEST_TARGET, "*")
c.perform()
print(c.getinfo(c.HTTP_CODE))

I get the following error:

AttributeError: trying to obtain a non-existing attribute: REQUEST_TARGET

A similar thing happens when I change c.setopt(c.REQUEST_TARGET, "*") to c.setopt(c.CURLOPT_REQUEST_TARGET, "*")

AttributeError: trying to obtain a non-existing attribute: CURLOPT_REQUEST_TARGET

Is there a way to use CURLOPT_REQUEST_TARGET with pycurl?

--------------- update -------------------

User barmar below gave me a hint to look at setopt_string for setting custom options. This looks promising. I tried this:

import pycurl
c = pycurl.Curl()
c.setopt(c.URL, "http://192.168.2.230")
c.setopt_string(266, "*")
c.perform()
print(c.getinfo(c.HTTP_CODE))

This however results in the following error:

TypeError: strings are not supported for this option

--------------- update 2 -------------------

Ended up making a pull request to add the feature

0

There are 0 best solutions below