• Register
0 votes
775 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.9k points

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.

36.1k points

Related questions

0 votes
1 answer 70 views
70 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 alecxe 7.5k points
0 votes
1 answer 158 views
158 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 alecxe 7.5k points
0 votes
1 answer 1.2K views
1.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
1 vote
2 answers 1.1K views
1.1K 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 713 views
713 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 alecxe 7.5k points