"unsupported URL" error given when accessing api gateway endpoint from swift - swift

I have the following code that is trying to invoke and api gateway function called endsession in swift:
client.endsessionPost(body: pleasegod!).continue ({ (task:AWSTask) -> Any? in
if let error = task.error {
print("Error occurred: \(error)")
return nil
}
if let result = task.result {
print("IT WORKED")
// Do something with result
}
return nil
})
It runs and completes but task error occurs and the print statement of what the error is says:
Error occurred: Error Domain=NSURLErrorDomain Code=-1002 "unsupported URL" UserInfo={NSUnderlyingError=0x618000056e60 {Error Domain=kCFErrorDomainCFNetwork Code=-1002 "(null)"}, NSErrorFailingURLStringKey=(null)/endsession, NSErrorFailingURLKey=(null)/endsession, NSLocalizedDescription=unsupported URL}
It seems to be saying the endpoint url provided is bad. The endpoint url was just copied and pasted from the endpoint of the api gateway deployment so I am not sure why that would be an unsupported url.
The endpoint has a format like so:
https://kco37e2fsa.execute-api.us-west-1.amazonaws.com/TheStage
When I visit this endpoint in a browser I notice it says:
{"message":"Missing Authentication Token"}
Which is strange since both my api gateway resources have Authorization set to None and API Key set to not required on all their methods. Is this missing authentication token a clue as to why I am getting unsupported URL errors in swift when invoking the API??

The url https://xxxxxxxxxx.execute-api.us-west-1.amazonaws.com/TheStage will only work if you have a GET method configured on the root resource, and if that is deployed to a stage called TheStage. (No sure if the API Id and/or stage are real). A browser will send a GET request if you just navigate to the URL.
I would recommend a tool like Postman for testing API calls; you can configure parameters, body, HTTP method, auth, etc.

Related

Google API Client Error: the caller does not have permission

I'm trying to use the Google API Client to gain access to a Google Doc. I get the following error:
googleapiclient.errors.HttpError: <HttpError 403 when requesting https://docs.googleapis.com/v1/documents/1Dc82X_w8UsyZnJe5JEh4E0wNdfbw-_nhVWXwgEJ4HVg?alt=json returned "The caller does not have permission". Details: "The caller does not have permission">
The error comes up in the file extract_text.py, which I got from here: https://developers.google.com/docs/api/samples/extract-text
Specifically, the error shows up at this line when it's obtaining the document's ID:
doc = docs_service.documents().get(documentId=documentID).execute()
The error states that my request has invalid authentication credentials (https://cloud.google.com/asset-inventory/docs/faq). I have made sure that I setup the OAuth correctly.

Get error to call HandshakeException:unable to get local issuer certificate(handshake.cc:363))

I get this error when i call api with get and post Method using http or dio.
How can i resolve this error.
This is my api calling code and below is console showing error

Sanic CORS Exception handler

I have tried to use Sanic_CORS in exception handler like error 404,
but I received CORS error
Access to XMLHttpRequest at 'http://backend:port/endpoint' from origin 'http://react_app:port' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.
There are no problems with valid endpoints.
My error handler
#app.exception(NotFound)
async def ignore_404s(request, exception):
return response.json({'message': "Oops, server error"},
status=404)
How can I implement Sanic_CORS for error handlers? Any ideas?
One option would be to just add the header into your response. Albeit, this is not using the sanic-cors package, but you really do not need it here.
#app.exception(NotFound)
async def ignore_404s(request, exception):
return response.json(
{'message': "Oops, server error"},
status=404,
headers={"Access-Control-Allow-Origin": "*"}
)

"Access is denied due to invalid credentials" REST API error. How to solve?

I followed the documentation here: and here: Trying to integrate to a Personality Insights service via Android Java.
However, after the app runs, and using the correct username and password as mentioned in the guide... (the guide is not clear (2nd bullet point in "Before you begin") on which set of credentials to use - It says get the "service credentials" and credentials from the new service created - I tried with both and both fail with the same error below.)
Error:
12-11 01:49:56.201 29584-29632/? I/CredentialUtils: JNDI string lookups is not available. 12-11 01:49:56.269 29584-29632/? D/NetworkSecurityConfig: No Network Security Config specified, using platform default 12-11 01:49:56.723 29584-29632/? D/OkHttp: --> POST https://gateway.watsonplatform.net/personality-insights/api/v3/profile?version=2017-10-13 http/1.1 (1297-byte body) 12-11 01:49:56.803 29584-29632/? D/OkHttp: <-- 401 Not Authorized https://gateway.watsonplatform.net/personality-insights/api/v3/profile?version=2017-10-13 (78ms, unknown-length body) 12-11 01:49:56.863 29584-29632/? E/WatsonService: POST https://gateway.watsonplatform.net/personality-insights/api/v3/profile?version=2017-10-13, status: 401, error: Not Authorized 12-11 01:49:56.865 29584-29632/? E/ERROR: Unauthorized: Access is denied due to invalid credentials
com.ibm.watson.developer_cloud.service.exception.UnauthorizedException: Unauthorized: Access is denied due to invalid credentials at com.ibm.watson.developer_cloud.service.WatsonService.processServiceCall(WatsonService.java:492) at com.ibm.watson.developer_cloud.service.WatsonService$2.execute(WatsonService.java:254) at com.upen.personalityapp.MainActivity$RetrieveFeedTask.doInBackground(MainActivity.java:105) at com.upen.personalityapp.MainActivity$RetrieveFeedTask.doInBackground(MainActivity.java:87) at android.os.AsyncTask$2.call(AsyncTask.java:306) at java.util.concurrent.FutureTask.run(FutureTask.java:237) at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:244) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607) at java.lang.Thread.run(Thread.java:761) 12-11 01:49:56.866 29584-29584/?
This is the code I am using; I am trying to pass a "text" input to the service.
service = new PersonalityInsights("2017-10-13");
service.setUsernameAndPassword("{myUsername}", "{myPassword}");
Profile profile = service.getProfile(text).execute();
System.out.println(profile);
return profile.toString();
I am using the com.ibm.watson.developer_cloud:personality-insights:3.8.0 dependency.
I tried connecting to the URL in the error (https://gateway.watsonplatform.net/personality-insights/api/v3/profile?version=2017-10-13 ) via a browser. It prompts for a username/password combo. I entered my details from my IBM Cloud Lite service but it throws the HTTP Error 405. Is this how it's supposed to work on the browser?
For someone in the future;
Instead of service.setUsernameAndPassword(username, password);, I tried service.setUsernameAndPassword("username", "password"); and it worked.

I am unable to access the Driver behavior service API's through any means like from node js, python, and by postman also

I am using one API to get the car probe data by date. This is the API
get method: https://api.ibm.com/driverinsights/datastore/carProbe/dateList?tenant_id=1ce29c2a-d408-4551-b1fd-815cf5810a02
Headers:
accept:application/json
content-type:application/json
Authorization:Basic NEZwMkd5bVc6cEdddHVqc1c1eVJaQVA=
I am getting response as
{
"httpCode": "404",
"httpMessage": "Not Found",
"moreInformation": "The requested URL was not found on this server"
}
the error message on your side says "404 Not Found".
Please check your hostname in the URL of Driver Behavior service.
[Correct]
"https://automotive.internetofthings.ibmcloud.com/driverinsights"
[Incorrect (yours)]
"https://api.ibm.com/driverinsights"
Please refer to official API documentation.
https://developer.ibm.com/api/view/id-261:title-IBM_Watson_IoT_Driver_Behavior#doc