I'm having a small issue with getting data from a API. I get the error "GET https://ipinfo.io/ 401 (Unauthorized)". Relevant code:
$.getJSON('//ipinfo.io', function(response){
console.log(response.loc)
var latlngIP = location['loc'].split(',');
var latIP = latlngIP[0];
var lngIP = lnglngIP[1];
API: https://ipinfo.io/
I did not exceed the 1000 uses per day limit.
EDIT:before you suggest it, adding https or http did not fix it.
You'll get a 401 for https if you do not have an access token. See https://ipinfo.io/pricing
EDIT: HTTPS access is now free: https://twitter.com/ipinfoio/status/779374440417103872
Related
I see the below error when I run my script to retrieve token data using Karate framework -
karate.org.apache.http.conn.HttpHostConnectException: Connection timed out: connect, http call failed after 21407 milliseconds.
Below is the Gherkin syntax written to extract token data -
* configure charset = null
* configure cookies = null
* header Content-Type = 'application/json'
* header Cookie = 'SMSESSION=' + SMSESSION
* header Connection = 'keep-alive'
Given path 'main-controller/v1/tokens'
When request ''
And method POST
And karate.waitForHttp(url)
Then status 200
And def token = response
And print 'NEW GENERATED TOKEN = ' + token
- Please be informed that url and SMSESSSION have been defined already in Background.
I have already tried the below configuration settings -
* configure proxy = 'http://my.proxy.host:8080'
* configure ssl = true
But none of these configurations resolved my issue.
I have even used karate.waitForHttp(url) in my feature file to try and wait for the Token API to respond back. Karate reports show that it waits for 72987 ms but still ends up with the same error again.
Can somebody help me resolve this issue? Thanks in advance!
Me and others are experiencing this error: SyntaxError: Unexpected token } in JSON at position 24 at JSON.parse (<anonymous>) while following this tutorial on JSON Web Tokens (LINK: https://www.youtube.com/watch?v=mbsmsi7l3r4&t=34s, around minute: 10:00)
The error appears during this POST request:
Content-Type: application/json
{
"username": "Kyle",
}
You can find the full code up to that point here:
https://github.com/emanuelefavero/json-web-tokens
There are 3 main files to watch for:
server.js
.env (I left the .env file in the github repository)
request.rest (I used this file to make POST request but you can use POSTMAN or other methods)
The error seems to be in server.js, specifically in the express-JWT method:
app.post('/login', (req, res) => {
// Authenticate User
// Create json web token
const username = req.body.username
const user = { name: username }
const accessToken = jwt.sign(user, process.env.ACCESS_TOKEN_SECRET)
console.log(accessToken)
res.json({ accessToken: accessToken })
})
The GET request is working fine.
While I'm trying to fix this error I'll still respond to any questions and provide project details if needed. Thank you.
Full Error Message:
SyntaxError: Unexpected token } in JSON at position 24
at JSON.parse (<anonymous>)
at parse (/Users/arch0n/Desktop/JWT/json-web-token/node_modules/body-parser/lib/types/json.js:89:19)
at /Users/arch0n/Desktop/JWT/json-web-token/node_modules/body-parser/lib/read.js:128:18
at AsyncResource.runInAsyncScope (node:async_hooks:199:9)
at invokeCallback (/Users/arch0n/Desktop/JWT/json-web-token/node_modules/raw-body/index.js:231:16)
at done (/Users/arch0n/Desktop/JWT/json-web-token/node_modules/raw-body/index.js:220:7)
at IncomingMessage.onEnd (/Users/arch0n/Desktop/JWT/json-web-token/node_modules/raw-body/index.js:280:7)
at IncomingMessage.emit (node:events:402:35)
at endReadableNT (node:internal/streams/readable:1343:12)
at processTicksAndRejections (node:internal/process/task_queues:83:21)
It appears the issue lies in the request you're making. You have a trailing comma in the JSON that you are sending in your request.
If you are new to using JSON & JavaScript, just try to remember that JavaScript objects !== JSON.
In JS Objects, you can have trailing commas. However, in JSON it will cause issues.
I have this:
<script>
function gettingJSON(){
$.getJSON("http://api.openweathermap.org/data/2.5/weather?q=London&appid=",function(json){
console.log(JSON.stringify(json));
});
}
</script>
when i run this, and look at my console, i get this erorr:
[Error] Failed to load resource: the server responded with a status of 401 (Unauthorized) (weather, line 0)
my api key matches the one in the openweathermap dashboard, so wondering y its not acc working. Maybe i'm missing something. any ideaS?
I think you just need to put your api key in the query string.
http://api.openweathermap.org/data/2.5/weather?q=London&appid=[HERE]
Moreover it requires a couple of hours to be activated and ready to use.
There are lots of question like my question but I didn't any working solution.
I am using AngularJS and WebApi2 in my application.
Here is the JS code which call the initial API.
(function (module) {
var baseUrl= "http://localhost:85";
module.constant('Config', baseUrl);
module.service('identities', ['$http', function ($http) {
var uri = baseUrl+ '/api/controller/GetRole';
var identities = {};
identities.get = function () {
var temp = $http.get(uri);
console.log(temp, "identities");
return temp;
}
return identities;
}]);
This function call the GetRole method in web API controller to retrieve user role.The output of this method is JSON with user details.
I have deployed the application on a server to port 85. When I run the application it's throwing error in Chrome:
net::ERR_CONNECTION_REFUSED
and in IE 11:
XMLHttpRequest: Network Error 0x2efd, Could not complete the operation due to error 00002efd
There is no log created in IIS for this request.
Using fiddler I got this in Raw with status code 502 in response.
The connection to 'localhost' failed.
Error: ConnectionRefused (0x274d).
System.Net.Sockets.SocketException No connection could be made because the target machine actively refused it 127.0.0.1:85.
I have also tried by disabling the CORS in chrome but no luck.
IF I use IP address of server instead of localhost as baseUrl in angular JS code then it's working fine.
Why it's not working with localhost?
I am doing a GET call and Error for me is 00002efd not 00002ef3.
I'm working on a Python API to handle REST calls to MongoDB. The API is based on Kule (and thus includes Bottle and PyMongo modules). The front-end is built using node.js. I have been developing and testing on localhost with the API, front-end, and MongoDB on different ports.
I have set up the API and have been trying to get CRUD requests to work. I can get these to work from a Python script as well as from Javascript running on Apache server. However, when I add the same code to the front-end, GET works, but POST fails with a 500 error.
This POST code works on the Apache server:
var myrequest=new XMLHttpRequest();
myrequest.onreadystatechange=function(){
if (myrequest.readyState==4){
if (myrequest.status==201){
alert(myrequest.responseText);
} else{
alert("An error has occured making the request");
}
}
}
myrequest.open("POST", "http://localhost:8080/items", true);
myrequest.setRequestHeader("Content-type", "application/json;charset=UTF-8");
myrequest.send(JSON.stringify({'name' : 'Name', 'description' : 'Description'}));
When I add this to the front-end, I get the following traceback from Kule:
Traceback (most recent call last):
File "C:\Python27\lib\site-packages\bottle.py", line 764, in _handle
return route.call(**args)
File "C:\Python27\lib\site-packages\bottle.py", line 1625, in wrapper
rv = callback(*a, **ka)
File "C:\Python27\lib\site-packages\bottle.py", line 1575, in wrapper
rv = callback(*a, **ka)
File "C:\Python27\lib\site-packages\kule\kule.py", line 64, in post_list
inserted = collection.insert(request.json)
File "C:\Python27\lib\site-packages\pymongo\collection.py", line 351, in insert
docs = [self.__database._fix_incoming(doc, self) for doc in docs]
TypeError: 'NoneType' object is not iterable
127.0.0.1 - - [24/Jun/2014 07:53:40] "POST /scenarios HTTP/1.1" 500 50
So, what am I doing wrong? Why does the Javascript break in node.js? I have GET working, but POST fails. Why?
Thanks!
I found my error.
myrequest.setRequestHeader("Content-type", "application/json;charset=UTF-8");
"Content-type" should be "Content-Type" with an upercase "T".
Silly mistake. Left as a note to others.