'Curl To Python Request (-d parameter)

Havin error to convert the below curl into python request.

curl -G "https://thethings.example.com/api/v3/as/applications//packages/storage/uplink_message"
-H "Authorization: Bearer $API_KEY"
-H "Accept: text/event-stream"
-d "limit=10"
-d "after=2020-08-20T00:00:00Z"
-d "field_mask=up.uplink_message.decoded_payload"

Python Request headers = { 'Authorization': f'Bearer {apiKey}',
'Accept': 'text/event-stream', 'Content-Type': 'application/json;charset=utf-8'}

data = { "order": { 'field_mask=up.uplink_message.decoded_payload' } }

response = requests.get(url, headers=headers) print(response.status_code) print(response.text)



Solution 1:[1]

you can try use this tool - https://curlconverter.com/

import os
import requests

API_KEY = os.getenv('API_KEY')

headers = {
    'Authorization': f"Bearer {API_KEY}",
    'Accept': 'text/event-stream',
}

params = (
    ('limit', '10'),
    ('after', '2020-08-20T00:00:00Z'),
    ('field_mask', 'up.uplink_message.decoded_payload'),
)

response = requests.get('https://thethings.example.com/api/v3/as/applications//packages/storage/uplink_message', headers=headers, params=params)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Tal Folkman