user8951490
user8951490

Reputation: 843

Python: Requests to local server not working

I am using the python library requests to attempt to send a post request to my local server. I have successfully installed and imported requests--I just can't seem to post or get data from my local server.

Both the server and my python program are on the same machine, the server is currently Django's development server.

What I am trying:

domain = 'localhost:8000'
user = 'username'
password = 'password'
data = 'some data to be sent'
r = requests.post(domain, data auth=(user,password))

Exception raised:

raise InvalidSchema("No connection adapters were found for '%s'" % url)
requests.exceptions.InvalidSchema: No connection adapters were found for 'localhost:8000'

I have done all the basic things like ensuring that the server was up and running. I have also tried to substitue localhost with 127.0.0.1:8000.

Upvotes: 2

Views: 3880

Answers (1)

Daniel Roseman
Daniel Roseman

Reputation: 599600

You need to use a proper URL including protocol:

domain = 'http://localhost:8000'

Upvotes: 6

Related Questions