尝试连接到vTiger时凭据无效

时间:2019-08-30 12:30:22

标签: python-3.x rest vtiger

我正在尝试使用python在vtiger CRM5中通过Web服务登录

将我的密钥和用户名放在参数中时,我只是得到一个INVALID_AUTH_TOKEN,但是当将其放入正文中时,我得到了INVALID_USER_CREDENTIALS。似乎更好,但效果不佳!

{'成功':False,'错误':{'代码':'INVALID_USER_CREDENTIALS','消息':'无效的用户名或密码'}}

# -*- coding: utf-8 -*-

import json
import requests
from hashlib import md5
from requests.auth import HTTPBasicAuth

api_url_base = 'http://crmaddress/webservice.php'
username = 'myusername'
accessKey = 'fghdhgfhfdhgfd'
headers =  {"ContentType":"application/x-www-form-urlencoded"}

response = requests.get(api_url_base,params={"operation":"getChallenge","username":username})
token =  json.loads(response.content.decode('utf-8'))['result']['token']

key = md5(accessKey.encode('utf-8')+token.encode('utf-8')).hexdigest()
print(key)

response = requests.post(api_url_base,data={"operation":"login","accessKey":key,"username":username,},auth=HTTPBasicAuth('myusername','mypassword'),headers=headers)
print(json.loads(response.content.decode('utf-8')))

1 个答案:

答案 0 :(得分:0)

我无法在不运行代码的情况下进行验证,但问题似乎出在某处

key = md5(accessKey.encode('utf-8')+token.encode('utf-8')).hexdigest()

此外,我建议不要创建一个包装类,而不是直接使用Web服务。请查看我在github上写的python3 wrapper。让我知道是否有帮助。