Pass query in php to python

-2

I'm trying to pass the php code given by api to make requests to python and I'm having some difficulties. In php the query is done as follows:

$query = http_build_query(array(
        'domains' => array(
            'google.com',
            'apple.com',
            'unknowndomain.com'
        )
    ));

And I did the following in python according to some examples I saw on the internet:

q = {'domains': 'g1.globo.com'}
query = urllib.parse.urlencode(q)

However, my api response is that no domain was sent:

  

{'status_code': 400, 'response': 'No Domains were provided'}

Does anyone know how to construct this query?

Example given by api in php:

$url = 'https://openpagerank.com/api/v1.0/getPageRank';
$query = http_build_query(array(
        'domains' => array(
            'google.com',
            'apple.com',
            'unknowndomain.com'
        )
    ));
$url = $url .'?'. $query;
$ch = curl_init();
$headers = ['API-OPR: YOUR-API-KEY-HERE'];
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$output = curl_exec ($ch);
curl_close ($ch);
$output = json_decode($output,true);

How is my code in python:

import requests
import urllib.parse

headers = {'API-OPR':'w0gswkcgcwcgs04o4kkcko0oo04k480co0gwg00k'}

q = {'domains': 'g1.globo.com'}

query = urllib.parse.urlencode(q)

request = requests.get('https://openpagerank.com/api/v1.0/getPageRank?', json={'query': query}, headers=headers)

result = request.json()

print(result)
    
asked by anonymous 18.12.2018 / 15:10

0 answers