-1

with exception of requests, are there other ways for doing a POST HttpRequest? I CAN ONLY USE DJANGO LIBS, so I cannot import requests.

In particular, I would like to pass the username and the password in the post request. something like:

data = {
    "username": "user",
    "password": "pass",
}
r = request.POST( data )

(please note that this code is just an example)

Anyone knows?

note: I'm using python 2.7

ChiaraM
  • 65
  • 1
  • 10
  • I cannot use `requests`. that request is for example. – ChiaraM Feb 12 '18 at 16:37
  • 4
    Try this https://stackoverflow.com/a/36678494/2578808 – Raj Subit Feb 12 '18 at 16:43
  • thank you @RajSubit, it is good but unfortunately I can import only django libs, nothing else.. – ChiaraM Feb 12 '18 at 16:50
  • 1
    @ChiaraM what exactly are you trying to do? – Ozgur Vatansever Feb 12 '18 at 16:55
  • @ozgur I have two systems that communicate among themselves; by the first one I have to send username and password to the second one (in a post request). I would already have done it if I could use `requests` ore some others libs. but I cannot, and I'm searching django libs for doing that – ChiaraM Feb 12 '18 at 16:59
  • 3
    What do u mean by "I can import only django libs". urllib is a built-in python library that can be used in django – Raj Subit Feb 12 '18 at 17:06
  • @RajSubit I mean that I can't import external packages.. 'chief' told me to use only django package; but, if it's built-in python library, than maybe it can solve my problem.. I try – ChiaraM Feb 12 '18 at 20:53

2 Answers2

0

You didn't set url.

data = {
  "username": "user",
  "password": "pass",
}

URL = 'http://example.com'
r = requests.post(URL, data=data)
Masoud
  • 1,008
  • 1
  • 9
  • 22
0

If you cannot use requests, try using urllib2 and urllib. What do you think about this?

post_data = {
  "username": "user",
  "password": "pass",
}
result = urllib2.urlopen('http://example.com', urllib.urlencode(post_data))
content = result.read()
vignz.pie
  • 173
  • 2
  • 14