Python Client connecting to HP ALM 12.20 - python

I'm trying to use requests to connect my python client to HP ALM so I can export Defects and Requirements.
My problem is that when I try to connect to ALM I get this error.
requests.exceptions.SSLError: HTTPSConnectionPool(host='hpalm.xxx.com', port=443): Max retries exceeded with url: /qcbin/authentication-point/authenticate (Caused by SSLError(SSLError("bad handshake: Error([('SSL routines', 'tls_process_server_certificate', 'certificate verify failed')])")))
my function is the following
def connection():
#HardCoded login to be deleted when tested and able to run with login verification
user = userPass.user()
pwd = userPass.passwd()
#Not sure if needed, need to test
encPwd = base64.standard_b64encode(pwd.encode('utf-8'))
print(encPwd)
userToEncode=user+':'+pwd
print("user2Encode : {0}", userToEncode)
#requests lib to ALM connection
headers = {
'cache-control': "no-cache",
'Accept': "application/json",
'Content-Type': "application/json"
}
authurl = almURL + "/authentication-point/authenticate"
res = requests.post(authurl, auth=HTTPBasicAuth(user,encPwd),headers = headers)
so far I've tried to follow this example:https://github.com/vkosuri/py-hpalm/blob/master/hpalm/hpalm.py
but when I do the verify=False I get :
InsecureRequestWarning: Unverified HTTPS request is being made. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings
InsecureRequestWarning)
and the following print of the log:
{'Date': 'Fri, 05 Mar 2021 17:36:51 GMT', 'X-Frame-Options': 'SAMEORIGIN', 'Content-Type': 'text/html; charset=ISO-8859-1', 'Cache-Control': 'must-revalidate,no-cache,no-store', 'Content-Length': '5937', 'Connection': 'close'}
any ideas what I'm doing wrong?
Thank you

There are alot of answers here on stack overflow about connecting to QC.
I would recommended you go through,
https://github.com/macroking/ALM-Integration/blob/master/ALM_Integration_Util.py
HP ALM results attachment and status update using python
These will help you understand the login process

Related

How can I recreate a mobile app api call using Python requests?

I used Charles Proxy to check the information being sent by a mobile app to its server, and now I am trying to use Python's request package to recreate the same call and get the information. I have three questions that I need help with.
Which of all the headers being shown in Charles do I need to use for my request?
I made the assumption that everything except the cookies, as this app does not require any sort of login to access the information. Am I correct in assuming this or should I add the cookies? If so, which ones?
I did try running a post request via python but got an SSL error. How can I overcome this error? I read about setting the option "verify=False" but that didnt work either. This is a mobile app, so not sure I could use my browser's cert, plus I have no idea how to do that either.
headers = {
"content-type": "application/json;charset=UTF-8",
"tlioscnx": "Wi-Fi",
"accept": "application/json",
"x-app-route": "SL-RSB",
"tliosloc": "gn=my_trips:list&ch=",
"tliosid": "15.6.1, iPhone13,3, 5.29.1",
"x-offer-route": "SL-SHOP",
"x-adapter": "mobile",
"x-acf-sensor-data": "2,i,UNUm0[...]",
"accept-encoding": "gzip;q=1.0, compress;q=0.5",
"accept-language": "en-US,en;q=0.9",
"content-length": "209",
"user-agent": "iPhone, iOS 15.6.1, 5.29.1, Phone"
}
json = {Json text as shown in Charles}
response. requests.post(url=URL, headers=headers,json=json)
response.raise_for_status()
print (response.json)```
Output: requests.exceptions.SSLError: HTTPSConnectionPool(host='api.delta.com', port=443): Max retries exceeded with url: /mwsb/service/shop (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed certificate in certificate chain (_ssl.c:992)')))'

Why doesn't Requests skip the certificate?

When executing a cUrl request :
curl -k -u test:123 -i -X POST -H "Content-Type: text/xml" "https://127.0.0.1:8085/q/status.xml"
I get an answer , everything works fine
But when executed via Requests:
import requests
headers = {
'Content-Type': 'text/xml',
}
response = requests.post('https://127.0.0.1:8085/q/status.xml', headers=headers, verify=False, auth=('test', '123'))
I get an error - requests.exceptions.SSLError: HTTPSConnectionPool(host='127.0.0.1', port=8085): Max retries exceeded with url: /q/status.xml (Caused by SSLError(SSLError(1, '[SSL: UNSUPPORTED_PROTOCOL] unsupported protocol (_ssl.c:997)')))
the issue has been resolved by downgrading the python version to 3.6

Max retries exceeded

I'm trying to fetch a request from urllib3 and my code works. However, few websites like https://hackershala.com and etc which uses different TLS version are not being able to be fetched.
I tried changing useragent, but it didn't work for obvious reasons.
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='hackershala.com', port=443): Max retries exceeded with url: / (Caused by SSLError(SSLError(1, '[SSL: TLSV1_ALERT_PROTOCOL_VERSION] tlsv1 alert protocol version (_ssl.c:852)'),))
My code is
import urllib3
http = urllib3.PoolManager()
url = input("Website URL: ")
r = http.request("GET", url, headers={
'User-Agent': 'Mozilla/5.0'
})
rp = r.status
print(rp)
You should probably add this line to configure your urllib3
import requests
import urllib3
requests.packages.urllib3.util.ssl_.DEFAULT_CIPHERS = 'ALL:#SECLEVEL=1'

Python's request module returns a proxy error

Sending a post request with proxies but keep running into proxy error.
Already tried multiple solutions on stackoverflow for [WinError 10061] No connection could be made because the target machine actively refused it.
Tried changing, system settings, verified if the remote server is existing and running, also no HTTP_PROXY environment variable is set in the system.
import requests
proxy = {IP_ADDRESS:PORT} #proxy
proxy = {'https': 'https://' + proxy}
#standard header
header={
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.87 Safari/537.36",
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8",
"Referer": "https://tres-bien.com/adidas-yeezy-boost-350-v2-black-fu9006-fw19",
"Accept-Encoding": "gzip, deflate, br",
"Accept-Language": "en-GB,en-US;q=0.9,en;q=0.8"
}
#payload to be posted
payload = {
"form_key":"1UGlG3F69LytBaMF",
"sku":"adi-fw19-003",
# above two values are dynamically populating the field; hardcoded the value here to help you replicate.
"fullname": "myname",
"email": "myemail#gmail.com",
"address": "myaddress",
"zipcode": "areacode",
"city": "mycity" ,
"country": "mycountry",
"phone": "myphonenumber",
"Size_raffle":"US_11"
}
r = requests.post(url, proxies=proxy, headers=header, verify=False, json=payload)
print(r.status_code)
Expected output: 200, alongside an email verification sent to my email address.
Actual output: requests.exceptions.ProxyError: HTTPSConnectionPool(host='tres-bien.com', port=443): Max retries exceeded with url: /adidas-yeezy-boost-350-v2-black-fu9006-fw19 (Caused by ProxyError('Cannot connect to proxy.', NewConnectionError(': Failed to establish a new connection: [WinError 10061] No connection could be made because the target machine actively refused it',)))
Quite a few things are wrong here... (after looking at the raffle page you're trying to post to, I suspect it is https://tres-bien.com/adidas-yeezy-boost-350-v2-black-fu9006-fw19 based on the exception you posted).
1) I'm not sure whats going on with your first definition of proxy as a dict instead of a string. That said, it's probably a good practice to use both http and https proxies. If your proxy can support https then it should be able to support http.
proxy = {
'http': 'http://{}:{}'.format(IP_ADDRESS, PORT),
'https': 'https://{}:{}'.format(IP_ADDRESS, PORT)
}
2) Second issue is that the raffle you're trying to submit to takes url encoded form data, not json. Thus your request should be structured like:
r = requests.post(
url=url,
headers=headers,
data=payload
)
3) That page has a ReCaptcha present, which is missing from your form payload. This isn't why your request is getting a connection error, but you're not going to successfully submit a form that has a ReCaptcha field without a proper token.
4) Finally, I suspect the root of your ProxyError is you are trying to POST to the wrong url. Looking at Chrome Inspector, you should be submitting this data to
https://tres-bien.com/tbscatalog/manage/rafflepost/ whereas your exception output indicates you are POSTing to https://tres-bien.com/adidas-yeezy-boost-350-v2-black-fu9006-fw19
Good luck with the shoes.

Python request to API gives SSL error

I am working with Python2.7 and I need to access a certain API (Nuagen): https://nuagenetworks.github.io/vsd-api-documentation/usage.html
In the documentation, they say the following:
Getting the API key.
To obtain and API key, the first step is to make a /me API call. This API call returns information about the account being used.
GET /me HTTP/1.1
X-Nuage-Organization: my company
Content-Type: application/json
Authorization: $AUTHORIZATION_STRING
The authorization string for the /me API MUST be formatted like the following:
$AUTHORIZATION_STRING = Basic base64($LOGIN:$PASSWORD)
So I try to build my requests in the folowing way;
import requests
url = 'https://an.ip.add.ress:8443/nuage/api/v4_0/me'
user = 'myuser'
passw = 'mypass'
cps = 'myorganization'
headers = {
"Authorization": "Basic d29jdTpjdXdv",
"Cache-Control": "no-cache",
"Content-Type": "application/json",
"X-Nuage-Organization": "csp",
}
response = requests.get(url, auth=(user, passw), headers=headers)
# Also tried with:
# response = requests.get(url, headers=headers)
However, I'm always getting this error:
requests.exceptions.SSLError: bad handshake: Error([('SSL routines', 'SSL3_GET_SERVER_CERTIFICATE', 'certificate verify failed')],)
Any idea on how to access this API with Python requests? Or any other way?

Categories

Resources