SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed when using requests - python-3.x

I am trying to send data via API but am receiving a SSL Certificate Verify Failed error with the following code:
import requests
url = "https://urlhere"
payload = "name=Test&description=Test&deadline=2017-12-31&disableEmail=true&campaignFilterId=00ad9cac28fa4c29fdb641c64b007a0b&type=Manager"
headers = {
'x-csrf-token': "TVUmiEALzVRQDkoQWbzdLI6l6NgftGoU",
'content-type': "application/x-www-form-urlencoded",
'cache-control': "no-cache",
'postman-token': "f8a9c488-0402-be25-aefb-cb2df65897f3"
}
response = requests.request("POST", url, data=payload, headers=headers)
print(response.text)
I am aware of using "verify=False" but understand that is not a recommended work around. What could be wrong here? I don't think it is the server since when I run this same API call in Postman it runs without issue.

Related

HP ALM API : Attaching file to run step through ALM REST API not working

We have fetched Run Steps details using ALM REST API.
(for reference ALM API Documentation
Same question is being asked in ALM community, Community Microfocus ALM
https://some.almserver.com/qcbin/rest/domains/DOMAIN/projects/PROJECT/runs/<run-id>/run-steps
and passed Run Step id to below API and tried to attach file using POST and PUT.
https://some.almserver.com/qcbin/rest/domains/DOMAIN/projects/PROJECT/runs/<run-id>/run-steps/<run-step-ID>/attachments
we are getting 404 response.
Bad request.
URL = "https://some.almserver.com/qcbin/rest/domains/DOMAIN/projects/PROJECT/runs/<run-id>/run-steps/<step-id>/attachments"
METHOD = "PUT"
HEADERS = {
'cache-control': "no-cache",
"Slug": "some.html",
'Content-Type': "application/octet-stream"
}
def attach_to_run_step():
f = open("/path/to/some.html", "rb")
response = requests.put(URL, headers=HEADERS, cookies=cookies, data=f.read())
print(response.content)
Expected : 200 response
Actual : 404 status code
I think you need to use the following URL for your POST request:
https://some.almserver.com/qcbin/rest/domains/DOMAIN/projects/PROJECT/run-steps/<run-step-id>/attachments (remove /runs/<run-id>)
Update:
Here is an example, generated from Postman:
import requests
url = "http://xxx.xxx.xxx.xxx:8080/qcbin/rest/domains/DEFAULT/projects/demo/run-steps/1263/attachments"
payload="<file contents here>"
headers = {
'Content-Type': 'application/octet-stream',
'Slug': '1.jpg',
'Cookie': 'JSESSIONID=<session>; ALM_USER=2e69...; LWSSO_COOKIE_KEY=PTKYM...; QCSession=MTQwM...; XSRF-TOKEN=3dfa4...'
}
response = requests.request("POST", url, headers=headers, data=payload)
print(response.text)
P.S. We are developing commercial platform for integrating various test frameworks with ALM, which is called Agiletestware Bumblebee, so you might want to have a look at it.

Google Oaut2 - Python using requests whiout Library

I am trying to authenticate not google by means of requests if I use the api but I don't know what I put in the "code" field and it will work, you can help me, or the code follows below.
import requests
url = "https://accounts.google.com/o/oauth2/token"
payload='grant_type=authorization_code&client_secret=xxxxx&client_id=xxxx&redirect_uri=https%3A%2F%2Fpushsistemas.com.br%2F&code='
headers = {
'content-type': 'application/x-www-form-urlencoded',
'Cookie': 'NID=219=RgUebbUM4k3WX0uQr8HVcIZkQ5-rMrb4HHnfnRzNTxUse776sG6-LItgXwpdv-MmaFYf3Tu4otJN-UfP70OzDtdnfam2dwAZkd6yMsr8BW_7lGE4FTaas9QkoG-hOMqXgYEHvI4YK39dWgXhWnL0E5LcsOv0DXnfjJ2kUf7VlTs; __Host-GAPS=1:jGXTa0ipDEC58oJF7pZwNBVeSXCQRw:3IRHy3GC9mAq4nqt'
}
response = requests.request("POST", url, headers=headers, data=payload)
This output
{
"error": "invalid_request",
"error_description": "Missing required parameter: code"
}
if it is not possible to do this way could you send me how to do it using the google library?

pisignage API login error: "This username/email is not registered or active"

From there api docs, I have created a request to login and get the token. The code is under below, it returns 401 . The credentials are right and I can log in from web, but through API I can not.
import requests
import json
params_dict = {
"email": "example#mail.com",
"password": "example",
"getToken": True
}
response = requests.post(
'https://example.piathome.com/api/session',
data=params_dict
# headers={'Content-type': 'application/json', 'accept': 'application/json'} returns 500
)
json_response = response.json()
print(json_response)
Make sure that the API endpoint is set to username.pisignage.com (not just pisignage.com).
And the headers are absolutely required. Request and Response types must be set to application/json.

Error calling CF API login one time passcode

I am working with the CF API RESTful services. Trying to get an access token from cloud foundry's UAA API using https://login..../oauth/token web method.
I have verified that headers & body content is correct, but calling the api always returns a 400 error code with message missing grant type.
I have implemented this call in Objective-C, Swift & now Python. All tests return the same result. Here is my code example in Python:
import json
import requests
import urllib
params = {"grant_type": "password",
"passcode": "xxx"
}
url = "https://login.system.aws-usw02-pr.ice.predix.io/oauth/token"
headers = {"Authorization": "Basic Y2Y6", "Content-Type": "application/json", "Accept": "application/x-www-form-urlencoded"}
encodeParams = urllib.parse.urlencode(params)
response = requests.post(url, headers=headers, data=encodeParams)
rjson = response.json()
print(rjson)
Each time I run this, I get the response
error invalid request, Missing grant type
Any help would be greatly appreciated.
Your code mostly worked for me, although I used a different UAA server.
I had to make only one change. You had the Accept and Content-Type headers flipped around. Accept should be application/json because that's the format you want back, and Content-Type should be application/x-www-form-urlencoded because that's the format you are sending.
See the API Docs for reference.
import json
import requests
import urllib
import getpass
UAA_SERVER = "https://login.run.pivotal.io"
print("go to {}/passcode".format(UAA_SERVER))
params = {
"grant_type": "password",
"passcode": getpass.getpass(),
}
url = "https://login.run.pivotal.io/oauth/token"
headers = {
"Authorization": "Basic Y2Y6",
"Content-Type": "application/x-www-form-urlencoded",
"Accept": "application/json"
}
encodeParams = urllib.parse.urlencode(params)
response = requests.post(url, headers=headers, data=encodeParams)
rjson = response.json()
print(json.dumps(rjson, indent=4, sort_keys=True))
I made a couple other minor changes, but they should affect the functionality.
Use getpass.getpass() to load the passcode.
Set the target server as a variable.
Pretty print the JSON response.
The only other thing to note, is that the OAuth2 client you use must be allowed to use the password grant type. It looks like you're using the same client that the cf cli uses, so if your UAA server is part of a standard Cloud Foundry install that is likely to be true, but if it still doesn't work for you then you may need to talk with an administrator and make sure the client is set up to allow this.

How to access secured soap endpoint in nodejs

Here is a service I need to access from nodejs:
https://test.matrikkel.no/endringsloggapi_v3/endringslogg/EndringsloggWebService?WSDL
I have the username and password.
How can I connect to service and issue requests?
Tried using 'soap' package in nodejs, but cannot understand where do I have to pass username and password.
Here is a working version done in python. Can anyone show how it works in nodejs.
import httplib, urllib
params = {}
headers = {"Content-type": "application/x-www-form-urlencoded",
"Accept": "text/plain",
"Authorization": "Basic 123"}
conn = httplib.HTTPSConnection("test.matrikkel.no")
conn.request("GET", "/endringsloggapi_v3/endringslogg/EndringsloggWebService?WSDL", params, headers)
response = conn.getresponse()
# print response.status, response.reason, response.read() to verify that call went through
conn.close()
Best Regards,
Edijs

Resources