• Register
0 votes

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.
6.9k points

Please log in or register to answer this question.

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.

38.6k points

Related questions

0 votes
1 answer 77 views
Problem: I am facing following error: post data should be bytes, an iterable of bytes, or a file object. it cannot be of type str.
asked Mar 14 Wafa Abu Yousef 6.1k points
0 votes
1 answer 9 views
Problem: Can anyone assist me with this issue : View must be a callable or a list/tuple in the case of include()?
asked Jun 20 Florina Gulnar 103k points
0 votes
0 answers 6 views
Problem: Is there somebody who can assist : Winerror 2 the system cannot find the file specified python?
asked Jun 23 Nahil 122k points
0 votes
1 answer 23 views
Problem: Is anyone available to assist me and resolve this issue? Python script to read a file line by line
asked May 5 Ifra 43.4k points
0 votes
1 answer 5 views
Problem: Global name 'filenotfounderror' is not defined
asked Jul 5 Shifa 18.2k points
0 votes
1 answer 13 views
Problem: How to download folder from google drive? Please assist me.
asked Jun 4 Rada Gracelynn 100k points
0 votes
1 answer 29 views
Problem: I installed the latest version of Python (3.6.4 64-bit) and the latest version of PyCharm (2017.3.3 64-bit). Then I installed some modules in PyCharm (Numpy, Pandas, etc), but when I tried installing Tensorflow it didn't install, and I ... some of the things which were suggested to other people, but nothing worked (this included installing Flask). How can I install Tensorflow? Thanks.
asked Apr 25 sumaiya simi 43.9k points
0 votes
1 answer 24 views
Problem: How to add 50 to the number stored under the 'gold' key?
asked Apr 12 ummesalma 29.1k points
0 votes
1 answer 154 views
Problem : I am unable to understand what am I missing here: Sort my_short_names in reverse alphabetic order. The sample output from the given program as below : ['Tody', 'Samy', 'Joey', 'Jany', 'Anny'] Below is my code for your reference : my_short_names = ['Jany', 'Samy', 'Anny', 'Joey', 'Tody'] my_short_names.sort() print(my_short_names)
asked Jan 8, 2020 alecxe 7.5k points
0 votes
1 answer 211 views
Problem: the error message says TypeError: unsupported operand type(s) for ** or pow(): 'str' and 'int' thanks for any insight you can provide...
asked Apr 11 ummesalma 29.1k points