Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Error posting with requests
#1
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?
Reply
#2
If I have to guess - self.email value is not what you expect :-)

Also, if you print response.text it may have more information
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#3
I tried. I did:
print(self.email)
and it printed out [email protected]
Reply
#4
try print(repr(self.email)) to check for any non-printing characters
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#5
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
Reply
#6
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)?
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#7
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?....
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  POST requests - different requests return the same response Default_001 3 1,938 Mar-10-2022, 11:26 PM
Last Post: Default_001
  Instagram Bot _ Posting Comments kristianpython 3 3,333 May-23-2020, 12:54 PM
Last Post: kristianpython
  Posting value from excel to Form (Python+Selenium) revanth 0 1,793 Feb-05-2020, 10:44 AM
Last Post: revanth
  Posting html values to views/models in Django Malt 1 2,157 Sep-04-2019, 01:44 PM
Last Post: fishhook
  error with requests rudolphyaber 9 5,058 May-20-2019, 06:19 PM
Last Post: rudolphyaber
  Error in requests.post debanilroy 3 5,425 Sep-18-2018, 06:15 PM
Last Post: snippsat
  An Error in Requests Module pratheep 3 11,911 Feb-06-2018, 05:17 PM
Last Post: pratheep

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020