I am trying to access checkpoint firewall by using it's API but for some reason I am getting HTTP Error 400: Bad Request, I have never had this before. Any ideas? Here is my code:
import json
import ssl
import urllib.request, urllib.parse, urllib.error
import urllib.request, urllib.error, urllib.parse
import requests
from requests.packages.urllib3.exceptions import InsecureRequestWarning
requests.packages.urllib3.disable_warnings(InsecureRequestWarning)
sslctx = ssl.create_default_context()
sslctx.check_hostname = False
sslctx.verify_mode = ssl.CERT_NONE
def checkpoint_api_call(cp_ip, port, command, json_payload, sid):
apiurl = 'https://' + cp_ip + '/web_api/' + command
req = urllib.request.Request(apiurl)
if sid == '':
req.add_header('Content-Type', 'application/json')
else:
req.add_header('Content-Type', 'application/json')
req.add_header('X-chkp-sid', sid)
try:
data1 = urllib.parse.urlencode(json_payload).encode("utf-8")
resp = urllib.request.urlopen(req, data=data1, context=sslctx)
res_code = resp.getcode()
return resp_output, res_code
except urllib.error.HTTPError as e:
print((str(e)))
main()
payload = {'user': admin, 'password': password}
response, res_code = checkpoint_api_call(x.x.x.x, 443, 'login', payload, '')
source https://stackoverflow.com/questions/70489137/how-do-i-fix-a-http-error-400-bad-request-in-python3
Comments
Post a Comment