• Register
0 votes
1.5k 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.
6 5 3
6,930 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.

9 7 4
38,600 points

Related questions

0 votes
1 answer 117 views
117 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 22 views
22 views
Problem: typeerror: '_io.textiowrapper' object is not subscriptable.
asked Feb 19 Dan phillip 2.4k points
0 votes
1 answer 273 views
273 views
Problem : When I try to run following command: python manage.py updatestats I get the error as below: “TypeError: int() argument must be a string, a bytes-like object or a number, not 'list'” I am unable to figure out ... ) File "/Users/alecxe/project/Dev/project_files/project/main/management/commands/updatestats.py", line 34, in handle unique_visits=display_unique_visits(hostname),)
asked Jan 2, 2020 alecxe 7.5k points
0 votes
1 answer 2.2K views
2.2K views
Problem : I am facing the issue in passing a function as a parameter to another function as follows typeerror: int() argument must be a string, a bytes-like object or a number, not 'nonetype'
asked Nov 18, 2019 peterlaw 6.9k points
0 votes
1 answer 5 views
5 views
Problem : Getting bellow python and django error , any help: 'virtualenv' is not recognized as an internal or external command, operable program or batch file.
asked 2 days ago Wafa Abu Yousef 2.3k points
1 vote
2 answers 4.4K views
4.4K views
Problem : Getting bellow python and django error 'virtualenv' is not recognized as an internal or external command, operable program or batch file.
asked Nov 8, 2019 peterlaw 6.9k points
0 votes
1 answer 3 views
3 views
Problem: how i can move on in dealing with this situation ? Iterator should return strings, not bytes (did you open the file in text mode?.
asked 2 days ago Wafa Abu Yousef 2.3k points
0 votes
1 answer 2.6K views
2.6K views
Problem : MySample.csv contains the below details : NAME Id No Dept Tommy 1 12 CS Jimmy 2 35 EC Bonny 3 21 IT Franky 4 61 EE And my Python file contains the below code : import csv myifile = open('mysample.csv', "rb") read = csv.reader(myifile) for row in read : ... in for row in read : _csv.Error: iterator should return strings, not bytes (did you open the file in text mode?) How should I fix it?
asked Jan 2, 2020 alecxe 7.5k points
0 votes
1 answer 1.3K views
1.3K views
Problem : When I run my Python code I get the following exception: _csv.error: iterator should return strings, not bytes (did you open the file in text mode?)
asked Nov 18, 2019 peterlaw 6.9k points