Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help with requests module
#1
Hi, I have a program I'm trying to switch modules from http.client to requests. The program takes a website through input and scans the index file to determine what filetype it is, pretty simple.

My issue is now that I switched to the requests module when I give it a website to scan it's telling me the index is all the possible filetypes so something is going wrong somewhere. I've been messing around and looking for answers for a few hours now so I figured somebody here might be able to tell me why.

I would guess it's somewhere between line 23 & 30.
#import http.client
import requests


files = ['index.html','index.php','index.js']

html = ["index.html", "Index is a html file"]
php = ["index.php", "Index is a php file"]
js = ["index.js", "Index is a javascript file"]

site = input("Enter URL-> ")

print ("Scanning " + "{}...\n".format(site))
print ("-"*60)

# HTTP.Client function
#def connection_status(site, index_file):
#    connection = http.client.HTTPSConnection(site)
#    connection.request("HEAD", index_file)
#    return connection.getresponse().status

# Requests fuction
def connection_status(site):
    connection = requests.head(site)
    return connection.status_code	


def scan(site, upload):
	status = connection_status(site)
	if status == 200:
		if upload == "index.html":
			print (html[0])
			print (html[1])
			print ("-"*60)
		elif upload == "index.php":
			print (php[0])
			print (php[1])
			print ("-"*60)
		elif upload == "index.js":
			print (js[0])
			print (js[1])
			print ("-"*60)					
		else:
			pass
	else:
		pass

for upload in files:
	scan(site, upload)

print ("")
print ("Scan complete!")
print ("")
exit()
Output:
Scanning http://localhost/... ------------------------------------------------------------ index.html Index is a html file ------------------------------------------------------------ index.php Index is a php file ------------------------------------------------------------ index.js Index is a javascript file ------------------------------------------------------------ Scan complete!
The index file in my localhost is index.html so that's all I'm expecting to return. Thanks to anyone taking the time to read this thread! Heart
Reply


Messages In This Thread
Help with requests module - by 0xB9 - Mar-14-2021, 05:13 AM
RE: Help with requests module - by buran - Mar-14-2021, 05:56 AM
RE: Help with requests module - by 0xB9 - Mar-14-2021, 06:35 AM
RE: Help with requests module - by buran - Mar-14-2021, 06:49 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  ModuleNotFoundError: No module named 'requests' Serg 18 3,037 Oct-29-2023, 11:33 PM
Last Post: Serg
  'urllib3' Module not found when import 'requests' spanz 5 10,683 Jan-06-2021, 05:57 PM
Last Post: snippsat
  ModuleNotFoundError: No module named 'requests' Martin 2 2,505 Oct-04-2020, 03:35 PM
Last Post: Martin
  Python requests module doesn not return status_code palo173 5 3,558 May-21-2019, 09:22 AM
Last Post: buran
  module requests, .text extension Truman 1 2,814 Jul-19-2018, 11:47 PM
Last Post: gontajones
  No module named 'requests.packages' runnerpaul 1 9,410 Aug-18-2017, 08:49 AM
Last Post: j.crater
  Requests module not installing Rayquaza51120 16 23,753 Nov-09-2016, 12:26 AM
Last Post: Blue Dog

Forum Jump:

User Panel Messages

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