如何通过Python请求传递curl选项?

如何通过Python请求传递curl选项?,python,curl,salesforce,python-requests,Python,Curl,Salesforce,Python Requests,我正在使用Desk.com api。限制之一是它们只允许调用500页记录。如果需要下载的页面超过500页,则需要使用curl-d选项对数据进行排序/过滤。通常,我通过将'since_id'选项设置为更高的id并下载500多个页面来实现这一点。这实质上是告诉桌面数据库向我发送多达500页的数据,因为_id=x 通常我使用os.popen()在python中运行它,但我想尝试将其切换到requests.get(),因为这在windows设备上应该可以更好地工作 os.popen("curl http

我正在使用Desk.com api。限制之一是它们只允许调用500页记录。如果需要下载的页面超过500页,则需要使用curl-d选项对数据进行排序/过滤。通常,我通过将'since_id'选项设置为更高的id并下载500多个页面来实现这一点。这实质上是告诉桌面数据库向我发送多达500页的数据,因为_id=x

通常我使用os.popen()在python中运行它,但我想尝试将其切换到requests.get(),因为这在windows设备上应该可以更好地工作

os.popen("curl https://www.URL.com -u username:password -H 'Accept:application/json' -d 'since_id=someID&sort_field=id&sort_direction=asc' -G")
对于请求,我尝试了许多不同的方法来运行它,包括像这样传递-d参数

payload = '-d 'since_id=someID&sort_field=id&sort_direction=asc' -G'
payload(alternate) = "{"-d":"'since_id=someID&sort_field=id&sort_direction=asc'","-G":""}"
requests.get('https://www.URL.com',auth=('username','password'),data=payload)
老实说,在我第二次尝试有效负载变量时,我不确定如何处理-G

I have tried the following.
    *including '-G' in the "-d" value of the json as well as putting it in its own dict
    *a few different variations including switching 'data' to 'params' on the requests.get line.
    *Adding/removing single quotes on the -d value in the get request

curl中的
-d
参数对应于请求中的查询参数。像这样的方法应该会奏效:

payload = {'since_id': 'someID', 'sort_field': 'id', 'sort_direction': 'asc'}
requests.get('https://www.example.com', params=payload)

我假设api使用基本身份验证

import requests
from requests.auth import HTTPBasicAuth
payload = {'something':'value'}
requests.get('http://myurl.com', auth=HTTPBasicAuth('user', 'pass'), params=Payload)

希望这能奏效

你为什么不:1。阅读CURL文档,了解这些标志的实际作用;然后2。阅读请求文档,了解如何实现相同的功能?信不信由你,例如,
-d
,虽然是一个非常合理的命令行标志,但通常不会成为请求头或JSON正文中的键。