I was able to resolve this issue
Can you please explain how?
In the above code I did two changes highlighted in bold.
1. site = ET.SubElement(credentials,'site', contentUrl = site)
2. req = requests.post(signin_url, xdata)
// instead of using req = Request(signin_url, xdata) and req = urlopen(req), I just replace it with line 2. above, and it worked for me.