def assembleRequest(data, method, URL, safe, headerDict, proxyDict, verbose):
# connect to the API endpoint, and send the data that was given
# note the response variable will hold all of the information received back from the server
try:
if method == "GET":
response = requests.get(URL, data, headers=headerDict,proxies=proxyDict, verify=safe)
elif method == "POST":
response = requests.post(URL, data, headers=headerDict, verify=safe, proxies=proxyDict)
elif method == "PUT":
response = requests.put(URL, data, headers=headerDict, verify=safe, proxies=proxyDict)
elif method == "DELETE":
response = requests.delete(URL, headers=headerDict, verify=safe, proxies=proxyDict)
elif method == "OPTIONS":
response = requests.options(URL, verify=safe, proxies=proxyDict)
elif method == "HEAD":
response = requests.head(URL, verify=safe, proxies=proxyDict)
else:
print "method not currently supported"
print "current methods: GET, POST, PUT, DELETE, OPTIONS, HEAD"
sys.exit()
print ""
# print response code (i.e. 404, 500, 200)
print response.status_code
if verbose:
# response headers are saved as a dictionary. Loop through the dictionary and print information.
for i in response.headers:
print i + ":", response.headers[i]
print ""
# output response body
print response.content
else:
pass
print ""
print ""
except requests.exceptions.Timeout:
print "Connection timeout - make sure a WAF or firewall rule is not blocking traffic."
except requests.exceptions.TooManyRedirects:
print "Too many redirects - URL may be bad"
except requests.exceptions.SSLError:
print "could not verify HTTPS certificate."
print 'pURL tries to verify HTTPS certificates. If using a proxy try "--unsafe"'
except requests.exceptions.RequestException as e:
print e
except Exception, e:
print "catastrophic failure see below for details"
print e
sys.exit(1)
评论列表
文章目录