Programmers learn & share
0 votes
563 views

Problem :

I am trying to convert my working Python 2.7 code into Python 3 code but I am facing following error
post data should be bytes, an iterable of bytes, or a file object. it cannot be of type str.
by (6.9k points)   | 563 views

1 Answer

0 votes

Solution :

Try following code:

urlCust = 'https://www.customdomain.com'
do = dict(param1="val1", param2="val2")

fo = urllib.parse.urlencode(do)
fo = fo.encode('utf-8')

req = urllib.request.Request(urlCust, fo)

Your issue lies in the way you were handling the dictionary.

by (36.1k points)  
2,245 questions
2,807 answers
60 comments
241 users