![](/img/trans.png)
[英]Why am I getting cURL error 77 doing multiple requests using Guzzle?
[英]Why might I be getting a 500 Error when using Python Requests, but not using cURL
我正在尝试使用python的请求进行Synchroteam API的基本实现。 我可以使用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
在此行上使用curl时,所有内容都会返回正确的信息:
curl -u domain:APIKEY -H "Accept: application/json" -H "Content-Type: application/json" https://apis.synchroteam.com/Api/v1/user/List
我的少量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的原因。 这些文档在这里: http : //api.synchroteam.com/rest.php
任何见解都会很棒,我真的希望它只是我所缺少的一些小东西。 谢谢。
这是我使用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)
只需更改身份验证!
缺口
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.