Php 为什么在使用Python请求而不是使用cURL时会出现500错误

Php 为什么在使用Python请求而不是使用cURL时会出现500错误,php,python,curl,python-requests,Php,Python,Curl,Python Requests,我正在尝试使用python的请求来实现SynchroTeamAPI的基本实现。我可以使用cURL作为概念证明来建立连接,并获得我想要的所有数据,但是使用请求,我可以使用我的凭据进入站点,但我得到的只是: 500 text/html; charset=utf-8 https://apis.synchroteam.com/Api/v1/user/list <!DOCTYPE html> <html> <head> <meta http-equiv="Con

我正在尝试使用python的请求来实现SynchroTeamAPI的基本实现。我可以使用cURL作为概念证明来建立连接,并获得我想要的所有数据,但是使用请求,我可以使用我的凭据进入站点,但我得到的只是:

500
text/html; charset=utf-8
https://apis.synchroteam.com/Api/v1/user/list

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title>Error</title>
</head>
<body>
    <h2>
        An error occurred while processing your request.
    </h2>
</body>
</html>

Process finished with exit code 0
我的一小段python代码如下:

import requests


apiurl = 'https://apis.synchroteam.com/Api/v1/user/list'
login = ("domain", "APIKEY")
headers = {'Content-Type': 'application/json'}

def run():
    r = requests.get(apiurl, auth=login, headers=headers)

    print r.status_code
    print r.headers['Content-type']
    print r.url
    print r.text

run()
所有Synchroteam文档都有PHP示例,但我看不出为什么我不能使用python。 文件如下:

任何洞察都会很棒,我真的希望这只是我错过的一些小东西。
谢谢。

这是我使用Postman生成的Python代码。我相信这会对你有帮助的

import requests

url = "https://apis.synchroteam.com/Api/v1/User/list"

payload = "{\n    \"status\":\"1\"\n}"
headers = {
'content-type': "application/json",
'accept': "application/json",
'authorization': "Basic ZGVtbzoxMjEyOThucDIwMDM=",
'cache-control': "no-cache",
'postman-token': "1a3839b6-db5b-0c07-be1a-2816f491476c"
}

response = requests.request("GET", url, data=payload, headers=headers)

print(response.text)
只要改变身份

尼克

你也试过设置
接受:
标题吗?我没有。你知道我应该让它接受什么吗?我不确定它现在挂断了什么。对于这个基本问题,很抱歉,这是我第一次使用任何HTTP或外部APIsUPDATE:我没有尝试过这个。我现在意识到这类似于卷曲线。非常感谢,这个问题困扰了我好几个小时。它没有给出关于这个问题的任何线索。感谢您的回复,我能够在ig0774的帮助下解决这个问题。我所需要的只是headers={'Accept':'application/json'},这就解决了所有问题。我以后可能不得不考虑做一些更高级的标题。
import requests

url = "https://apis.synchroteam.com/Api/v1/User/list"

payload = "{\n    \"status\":\"1\"\n}"
headers = {
'content-type': "application/json",
'accept': "application/json",
'authorization': "Basic ZGVtbzoxMjEyOThucDIwMDM=",
'cache-control': "no-cache",
'postman-token': "1a3839b6-db5b-0c07-be1a-2816f491476c"
}

response = requests.request("GET", url, data=payload, headers=headers)

print(response.text)