Pycurl saves print in terminal

I am starting to use Python and Pycurl to test a webpage for testing purposes. However, pycurl continues to print the returned html in the terminal, which makes stress testing even longer than necessary. One such pycurl code that I use is posted below. Is there a way to run pycurl without having to print or write the result anywhere? Any help would be appreciated.

p = pycurl.Curl() p.setopt(pycurl.POST, 0) p.setopt(pycurl.COOKIE, sessioncookie) p.setopt(pycurl.URL, 'http://example.com/logoff.php') p.perform() p.close() 
+7
source share
4 answers

Pycurl's documentation is terrible, but I think you want to set WRITEFUNCTION to a function that does nothing, for example.

 p.setopt(pycurl.WRITEFUNCTION, lambda x: None) 

In addition, I want to indicate for the record that I thought the โ€œSET does everythingโ€ API came out with VMS. Gaaah.

+19
source

You can also try?

 devnull = open('/dev/null', 'w') p.setopt(pycurl.WRITEFUNCTION, devnull.write) 

or just a function that does nothing.

+3
source

I was not lucky with both of the approaches listed here. Both of them lead to the following error:

 pycurl.error: (23, 'Failed writing body (0 != 108)') 

According to the documentation, both lambda x: None and devnull.write should be good options:

The WRITEFUNCTION callback can return the number of bytes written . If this number is not equal to the size of the byte string, this means an error, and libcurl will abort the request. Returning No is an alternative way of indicating that the callback destroyed the entire string passed to it and therefore succeeded.

http://pycurl.sourceforge.net/doc/callbacks.html#WRITEFUNCTION

However, in my project, I had to do the following to fix this problem:

 c.setopt(pycurl.WRITEFUNCTION, lambda bytes: len(bytes)) 

In other words, it was not necessary to return the number of bytes recorded during the scan. devnull.write really returns the number of bytes written, but I have not looked at that. Perhaps there is a problem with bytes and strings.

Please note that I am using Python 3. I assume this is not the case with Python 2.

+1
source

To hide the output, change VERBOSE to 0:

 p.setopt(pycurl.VERBOSE, 0) 
0
source

All Articles