python-3.xrestvtiger

Invalid credentials when trying to connect to vTiger


I'm trying to log in via webservice within vtiger CRM5 with python

When putting my key and user name in params, I just get an INVALID_AUTH_TOKEN, but when putting it into body, I get INVALID_USER_CREDENTIALS. Which seems better but not quite working !

{'success': False, 'error': {'code': 'INVALID_USER_CREDENTIALS', 'message': 'Invalid username or password'}}

# -*- 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')))

Solution

  • I cannot verify without running the code, but the problem seems to be somewhere along

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

    Also, instead of directly using the webservice, I would recommend creating a wrapper class. Please check out a python3 wrapper I wrote at github. Let me know if this helps.