• Register
0 votes
1.2k 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

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 95 views
95 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 218 views
218 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.7K views
1.7K 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 2.9K views
2.9K 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