Python 3 urllib produces TypeError: POST data should be bytes or an iterable of bytes. It cannot be of type str

From the docs Note that params output from urlencode is encoded to bytes before it is sent to urlopen as data:

data = urllib.parse.urlencode(d).encode("utf-8")
req = urllib.request.Request(url)
with urllib.request.urlopen(req,data=data) as f:
    resp = f.read()
    print(resp)

Try this:

url = 'https://www.customdomain.com'
d = dict(parameter1="value1", parameter2="value2")

f = urllib.parse.urlencode(d)
f = f.encode('utf-8')

req = urllib.request.Request(url, f)

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