0
import requests
import json

url = 'mywebsite/test.php'
myobj = data = {"username" : "test", "password" : "1234"}


myobj = json.dumps(myobj)
x = requests.post("loginUser",url, data = myobj)

print(x)

I get the following error:

Traceback (most recent call last):
File "main.py", line 55, in <module> x = requests.post("loginUser",url, data = myobj) TypeError: post() got multiple values for argument 'data'

Can anyone help with this?

5
  • 2
    The call signature is requests.post(url, data=None, json=None, **kwargs). You use "loginUser" as the url, and your url as data, so double data. What is your intent for "loginUser"? What is it supposed to do? Commented Sep 14, 2021 at 15:08
  • It is the method I am trying to call in my php script I am connecting to Commented Sep 14, 2021 at 18:29
  • That will depend on how your test.php is written. My guess is that requests.post(url, data = myobj) will work - assuming that your test.php hard codes the call to loginUser. Commented Sep 14, 2021 at 18:35
  • This is my php code: docs.google.com/document/d/… Commented Sep 14, 2021 at 19:04
  • I am so sorry but I just figured out that I used the wrong terminology when saying that loginUser was a method. I should have said it was a function. Commented Sep 15, 2021 at 1:18

3 Answers 3

1

Look at the docs:

https://docs.python-requests.org/en/latest/api/

requests.post(url, data=None, json=None, **kwargs)[source]
Sends a POST request.

Parameters: 
url – URL for the new Request object.
data – (optional) Dictionary, list of tuples, bytes, or file-like object to send in the body of the Request.
json – (optional) json data to send in the body of the Request.
**kwargs – Optional arguments that request takes.
Returns:    
Response object

and so your command should be:

myobj = json.dumps(myobj).encode("ascii")
x = requests.post(url = url, data = myobj)

or without using json.dumps:

x = requests.post(url = url, json = myobj)

What exactly is "loginUser" for in this case? is that a URI route, field, or parameter?

Sign up to request clarification or add additional context in comments.

1 Comment

"loginUser" is the function in my php script that i want to send the data to
0

I'm just learning python myself and have used requests a bit.

I've always put the url at the beggining and payload at the end:
i.e Should "LoginUser" go at the end?

1 Comment

As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.
0

I have fixed it. Problem was that I didn’t put http:// in front of the url and I didn’t format my JSON request the way my php was expecting.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.