Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

Python 

Error trying to connect to a web with httplib in python?

I am trying to connect a python script with a simple website that I made in html and php to test through httplib.


The python script for the connection is as follows:

Code
import http.client as ht
import urllib.parse as ub

openConn=ht.HTTPConnection('127.0.0.1:80')
headers = {'Content-Type':'application/x-www-form-urlencoded','Accept':'text/plain'}
param = ub.urlencode({'usertext':'jhona','passtext':'shaki11'})
openConn.request('GET','htttp://localhost/Test_brut/html_te/php/backdoc.php',param,headers)  
resp=openConn.getresponse()
read_resp=resp.read().decode()
print(read_resp)
clarification: I had to put htttp with triple 't' to be able to make the post since hack forums does not let me put anything similar to link I no longer have 50 posts, so ignore that


The php document that receives the connection is as follows:

Code
$username = $_GET['usertext'];
$password = $_GET['passtext'];

if(isset($username)&& $username=='jhona'){
if(isset($password) && $password == 'shaki11'){

   $open_file = fopen('script_ht.html','r');
   $read_f='';

   while(!feof($open_file)){
       $lin=fgets($open_file);
       $read_f=$read_f.$lin;
   }

   fclose($open_file);

   echo 'WELCOME '.$username.'<br>'.$read_f;
}

else{
   echo "THE PASS IS INCORRECT";
}

}
else{
   echo 'No exist';
}


However, when I try the getresponse() of httplib.client I get the answer the following error:

Code
Undefined index: usertext in on line 4

Undefined index: passtext in on line 5

No exist

I know that the error is in the python script and not in the php document because when I connect from an HTML page entering the user and the password I get the Welcome message, but when I do it from the python script I get the error .

Anyone here know what I am doing wrong?
Why not just touch the url with your parameters hard coded into it?

Code
import requests

usertext = "YOUR STRING"
passtext = "YOUR STRING"

r = requests.get("htttp://localhost/Test_brut/html_te/php/backdoc.php?usertext=%s&passtext=%s" % (usertext, passtext))
print(r.response)

That last part will print [200] by default if the request is successful but the requests library could grab all kinds of things like session cookies etc.


Possibly Related Threads...
Thread / Author Replies Views Last Post
[Python] by Bass_ReevesAug 20, 2023 01:44 AM 9 632 Aug 20, 2023 01:44 AM
Last Post: Lucky4L
[Python] by AeroBlueJun 29, 2019 04:37 PM 7 486 Jun 29, 2019 04:37 PM
Last Post: TGilb94
[Python] by 0xB9May 17, 2018 01:33 AM 2 87 May 17, 2018 01:33 AM
Last Post: Mohinder