How to sett the HTTP_VERSION in Pycurl for use with Mindtouch CURL interface

582 Views Asked by At

I am trying to access a Mindtouch Wiki using Python. I am trying to use pycurl to do this as the sparse Mindtouch documentation does give CURL command line examples. I found by trial and error that the operation needs the --http1.0 option to be put n the CURL command line in order for the operation to succeed. However I have not found out how to set this option in pycurl.

What I get is:

c.setopt(c.HTTP_VERSION_1_0, True)
AttributeError: trying to obtain a non-existing attribute

When using CURL on the command line I use a hand coded XML file and refer to it using the -T option. However it would be easier to start with the XML as a string. Any additional insight into doing that in pycurl would be great.

Alternatively, if there is a better way of doing it than pycurl I would be happy to hear of it.

2

There are 2 best solutions below

0
On

As an alternative to pycurl, you could try the requests HTTP library.

Here's a working example that gets the JSON output of a specific page.

import requests

api_url = "https://success.mindtouch.com/@api/deki/pages/1835/?dream.out.format=json"

response = requests.get(api_url)

print(response.json())

This gets the page endpoint for MindTouch's API calls article.

You can also include credentials, like so:

import requests

api_url = "https://success.mindtouch.com/@api/deki/pages/1835/?dream.out.format=json"

creds = ("username", "password")
response = requests.get(api_url, auth=creds)

print(response.json())
1
On

It should be:

c.setopt(pycurl.HTTP_VERSION, pycurl.CURL_HTTP_VERSION_1_0)

See curl official documentation.