Python Forum

Full Version: Error posting with requests
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
So I've created a code that posts something on a website. It works perfectly fine when I run it like this (+ other code but that isnt important):
# Above is other (correct) code, wich isnt important
        payload = {
            "firstName": self.first_name,
            "lastName": self.last_name,
            "email": "[email protected]",
            "dateOfBirth": self.dob,
            "termsAccepted": 'true',
            "variantId": int(self.size),
            "articleId": int(self.url),
        }
        response = requests.post(url2, payload, proxies=proxies)
        print(response.status_code)
It prints out '200', so this code works.
But when I run it with the (SAME) email being a variable.
So like this:
# Above is other (correct) code, wich isnt important
        payload = {
            "firstName": self.first_name,
            "lastName": self.last_name,
            "email": self.email,
            "dateOfBirth": self.dob,
            "termsAccepted": 'true',
            "variantId": int(self.size),
            "articleId": int(self.url),
        }
        response = requests.post(url2, payload, proxies=proxies)
        print(response.status_code)
it prints out (500), with the reason: internal server error.

Does someone know why?
If I have to guess - self.email value is not what you expect :-)

Also, if you print response.text it may have more information
I tried. I did:
print(self.email)
and it printed out [email protected]
try print(repr(self.email)) to check for any non-printing characters
it printed out this:
'[email protected]'

I've tried it with this email: [email protected], and it worked. So i think it's that 2 that screws it up. But i need my script to work with emails like: [email protected] too. So I do need a fix
initially you claimed it worked with same address... Now it turns it was not the same. what is the result if you try the first snippet with the SAME e-mail address. or whas it working with self.email='[email protected]'?
Also what url/API you send request to (i.e. are there any docs)?
It was the same address.........

I've tried it too with a different addres, but that did work. but when I used the same addres but as a variable, it didnt work.

(Mar-28-2020, 09:43 PM)julio2000 Wrote: [ -> ]It was the same address.........

I've tried it too with a different addres, but that did work. but when I used the same addres but as a variable, it didnt work.
It DID work with self.email = '[email protected]'. And it DIDN'T work with self.email = '[email protected]'

so no one knows the answer?....