i'm tring to use python 3 insted of python 2 in ZOHO CRM API.
in python 2 the code that works is:
import urllib
import urllib2
module_name = 'Leads'
authtoken = '[authtoken]'
valueToSeek = 'test'
params = {'authtoken':authtoken,'scope':'crmapi','criteria':'(((Last
Name:'+valueToSeek+')'}
final_URL = "https://crm.zoho.com/crm/private/xml/Leads/searchRecords"
data = urllib.urlencode(params)
request = urllib2.Request(final_URL,data)
response = urllib2.urlopen(request)
xml_response = response.read()
in python 3 the code that doesn't works is:
import urllib
import urllib.request
from urllib.request import urlopen
import urllib.parse
module_name = 'Leads'
authtoken = '[authtoken]'
valueToSeek = 'test'
params = {'authtoken':authtoken,'scope':'crmapi','criteria':'(((Last
Name:'+valueToSeek+')'}
final_URL = 'https://crm.zoho.com/crm/private/xml/Leads/searchRecords'
data = urllib.parse.urlencode(params)
request = urllib.request.Request(final_URL,data)
response = urllib.request.urlopen(request)
xml_response = response.read()
print (xml_response)
i get this:
Traceback (most recent call last): File "C:/Users/Darda_000/AppData/Local/Programs/Python/Python36-32/zohoTestPY3.py", line 12, in response = urllib.request.urlopen(request) File "C:\Users\Darda_000\AppData\Local\Programs\Python\Python36-32\lib\urllib\request.py", line 223, in urlopen return opener.open(url, data, timeout) File "C:\Users\Darda_000\AppData\Local\Programs\Python\Python36-32\lib\urllib\request.py", line 524, in open req = meth(req) File "C:\Users\Darda_000\AppData\Local\Programs\Python\Python36-32\lib\urllib\request.py", line 1248, in do_request_ raise TypeError(msg) TypeError: POST data should be bytes, an iterable of bytes, or a file object. It cannot be of type str.
What is my mistake?