Error saying "Expecting value: line 1 column 1 (char 0) " when retrieving venue for the tip with the greatest number of agree counts - api

I am using foursquare api to retrieve the venue for the tip with the greatest number of agree counts using requests library in jupyterLab but I am getting this error "Expecting value: line 1 column 1 (char 0)". I am new to using api calls so please help me on how to fix this error. Below is my code:
tip_id = '5ab5575d73fe2516ad8f363b' # tip id
# define URL
url = 'http://api.foursquare.com/v2/tips/{}?client_id={}&client_secret={}&v={}'.format(tip_id, CLIENT_ID, CLIENT_SECRET, VERSION)
# send GET Request and examine results
result=requests.get(url).json()
# .get(url).json()
print(result['response']['tip']['venue']['name'])
print(result['response']['tip']['venue']['location'])
error:
[Error

Related

Download a page doesn't return a status code

I have found a page I need to download that doesn't include an http status code in the returned headers. I get the error: ParseError: ('non-integer status code', b'Tag: "14cc1-5a76434e32f9e"') which is obviously accurate. But otherwise the returned data is complete.
I'm just trying to save the page content manually in a call back: afilehandle.write(response.body) sort of thing. It's a pdf. Is there a way I can bypass this and still get the contents of the page?
The returned example that also crashed fiddler. The first thing in the header is Tag.
Tag: "14cc1-5a76434e32f9
e"..Accept-Ranges: bytes
..Content-Length: 85185.
.Keep-Alive: timeout=15,
max=100..Connection: Ke
ep-Alive..Content-Type:
application/pdf....%PDF-
1.4.%ÓôÌá.1 0 obj.<<./Cr
eationDate(D:20200606000
828-06'00')./Creator(PDF
sharp 1.50.4740 \(www.pd
fsharp.com\))./Producer(
PDFsharp 1.50.4740 \(www
.pdfsharp.com\)).>>.endo
bj.2 0 obj.<<./Type/Cata
log./Pages 3 0 R.>>.endo
bj.3 0 obj.<<./Type/Page
s./Count 2./Kids[4 0 R 8
0 R].>>.endobj.4 0 obj.
<<./Type/Page./MediaBox[
0 0 612 792]./Parent 3 0
R./Contents 5 0 R./Reso
urces.<<./ProcSet [/PDF/
Text/Ima.... etc
Note: For any not familiar with PDF file structure %PDF-1.4 and everything after is the correct format for a PDF document. Chrome downloads the PDF just fine even with the bad headers.
In the end, I modified the file twisted/web/_newclient.py directly to not throw the error, and use a weird status code that I could identify:
def statusReceived(self, status):
parts = status.split(b' ', 2)
if len(parts) == 2:
version, codeBytes = parts
phrase = b""
elif len(parts) == 3:
version, codeBytes, phrase = parts
else:
raise ParseError(u"wrong number of parts", status)
try:
statusCode = int(codeBytes)
except ValueError:
# Changes were made here
version = b'HTTP/1.1' #just assume it is what it should be
statusCode = 5200 # deal with invalid status codes later
phrase = b'non-integer status code' # sure, pass on the error message
# and commented out the line below.
# raise ParseError(u"non-integer status code", status)
self.response = Response._construct(
self.parseVersion(version),
statusCode,
phrase,
self.headers,
self.transport,
self.request,
)
And I set the spider to accept that status code.
class MySpider(Spider):
handle_httpstatus_list = [5200]
However, in the end I discovered the target site behaved correctly when accessed via https, so I ended up rolling back all the above changes.
Note the above hack would work, until you updated the library, at which point you would need to reapply the hack. But it could possibly get it done if you are desparate.

If response contains the word 'any' then match response contains is failing

Let's say if I am having a scenario like
Scenario: Call a Get API and validate the response
Given path 'myteam'
When method get
Then status 201
And print response
And match response contains { teamFeature: 'pick any feature'}
And my API response is
{
"id": "6c0377cd-96c9-4651-bcc8-0c9a7d962bc3",
"teamFeature": "pick any feature"
}
Then I am getting the error like
example.feature:19 - javascript evaluation failed: feature'}, :1:9 Missing close quote
feature'}
^ in at line number 1 at column number 9
If my API response does not contain the word 'any' and I change the match statement then it is working fine. Looks like I need to escape the the word 'any' somehow.
May I know how can I escape the word 'any'?
Not sure if this is a bug in Karate.
Tried to call
com.intuit.karate.Match match = new com.intuit.karate.Match("pick any feature");
System.out.println(match.contains("pick any feature"));
And received following error
Exception in thread "main" java.lang.RuntimeException: javascript
evaluation failed: pick any feature, :1:5 Expected ; but found
any pick any feature
^ in at line number 1 at column number 5 at com.intuit.karate.ScriptBindings.eval(ScriptBindings.java:152) at
com.intuit.karate.ScriptBindings.updateBindingsAndEval(ScriptBindings.java:142)
at
com.intuit.karate.ScriptBindings.evalInNashorn(ScriptBindings.java:127)
at com.intuit.karate.Script.evalJsExpression(Script.java:423) at
com.intuit.karate.Script.evalKarateExpression(Script.java:337) at
com.intuit.karate.Script.evalKarateExpression(Script.java:203) at
com.intuit.karate.Match.(Match.java:67) at
com.intuit.karate.Match.(Match.java:53)
Yes this is a bug in Karate, we've opened an issue: https://github.com/intuit/karate/issues/678
The workaround suggested by #BabuSekaran will work:
* def response = { foo: 'a any b' }
* def temp = { foo: 'a any b' }
* match response contains temp

How to return distinct multi-word strings from blocks of usage log text with POSIX?

First time poster and still learning the ropes, so I apologize if the description below is overly verbose.
I have a database of usage logs I'm pulling data from via various pre-parsed fields. This query is intended to return the count of how many times a distinct error signature was logged over a given period of time. Each logged error is assigned a signature_id, errors of the same type are all assigned the same signature_id. One of the fields I'm returning in my query, message, returns the entire message stack trace/block of usage log text.
I want my query to group by signature_id, which is a pre-parsed field in the table I'm selecting from. I'm struggling to make it work because, while similar error types are assigned the same signature_id', every usage log differs slightly due to the timestamp of when the message was logged. So my query is grouping bymessageinstead ofsignature`.
EX: Of what my query returns if I return the entire usage log message
signature_id
b2dea422
message
2019-01-17 18:01:52,130 ip-BLANK [WARN ][159] [request_id=00e74d7c] Type=Blank.Multiverse.Web.Mvc.Attributes.Usage+UsageLoggingException Message=UsageLogContext not present in HttpContext.Current.Items Data: Signature=b2dea422 Stack Trace: at Blank.Blank.Web.Mvc.Attributes.Usage.GetUsageLogContext() at Blank.Blank.Web.Mvc.Attributes.Usage.AddData(Object data)
count
1
signature_id
b2dea422
message
2019-01-17 16:21:36,681,130 ip-BLANK [WARN ][38] [request_id=c140f8ea] Type=Blank.Multiverse.Web.Mvc.Attributes.Usage+UsageLoggingException Message=UsageLogContext not present in HttpContext.Current.Items Data: Signature=b2dea422 Stack Trace: at Blank.Blank.Web.Mvc.Attributes.Usage.GetUsageLogContext() at Blank.Blank.Web.Mvc.Attributes.Usage.AddData(Object data)
count
1
I mentioned above that every usage log differs due to the timestamp of when a given message was logged, but similar error types are assigned the same signature_id. Similar error types also share the same Exception Message=...
EX: Every time a message is logged with signature_id=ab7d890pq, it will also have Exception Message=Cannot read property 'get' of undefined in the message block.
Since the table I'm selecting from doesn't have a pre-parsed exception_message field, I want to parse out the Exception Message= string so my GROUP BY will return the count of distinct logged signature_id's and a column with the exception message is for each distinct signature.
My current query shown below begins to parse out the exceptionmessgage string, but I can't get it to return the entire string:
SELECT CASE
WHEN sourcecategory = 'source_hello_world_category' THEN 'hwCategory'
END AS Service,
signature,
NULLIF(SUBSTRING(REGEXP_SUBSTR(message, 'Message=\\w+[[:space:]]+'), 9), '') AS exceptionmessage,
count(*)
FROM user_usage_logs
WHERE (signature IS NOT NULL
AND signature NOT IN ('ccce9e73',
'787dd1b5',
'17fc66bc',
'ca384d1f',
'20121ecb',
'ccce9e73'))
AND sourcecategory IN ('source_hello_world_category')
AND messagetime > (getdate() - 1)
GROUP BY signature,
sourcecategory,
exceptionmessage
ORDER BY COUNT DESC
LIMIT 10;
The code shown above returns:
signature_id exceptionmessage count
b1det422 Cannot 31,321
330ope77 Unauthorized 1,207
53m6m466 Reference 311
This is an example of I want returned:
signature_id exceptionmessage count
b1det422 Cannot read property 'get' of undefined Stack 31,321
330ope77 Unauthorized access response for many users 1,207
53m6m466 Reference cannot be set to an empty.object.3 311

Why do I keep getting a 500 error when I calling the SoftLayer_Billing_Invoice::getItems interface?

Recently I was developing a project that relied on the softlayer interface. I want get the invoice details about the bare metal server. But I keep getting a 500 error when I call the SoftLayer_Billing_Invoice::getItems interface. And other interfaces are normal.
regards~
code show as below:
client = SoftLayer.create_client_from_env(username="username",
api_key="api_key",
proxy="proxy")
sl_billing_invoice = client['Billing_Invoice']
try:
result = sl_billing_invoice.getItems(id=id)
print result
except SoftLayer.SoftLayerAPIError as sl_exc:
msg = 'result:(%s, %s)' % (sl_exc.faultCode, sl_exc.faultString)
print msg
Return error message as blow:
result:(500, 500 Server Error: Internal Server Error)
The issue is likely that your request is returning a big amount of data, this case commonly happens with invoices and billing items. In order to solve that issue you have the followings options:
Reduce the amount of data through object-masks or using object-filters.
Use pagination (result limits) in order to fetch less data in the request.
result = sl_billing_invoice.getItems(limit=50, offset=0, id=id)
Softlayer doc and similar questions:
https://softlayer.github.io/blog/phil/how-solve-error-fetching-http-headers/
https://softlayer-python.readthedocs.io/en/latest/api/client.html?highlight=limit#making-api-calls
Softlayer getAllBillingItems stopped working?
Getting 500 Internal Server Error from Account.getVirtualGuests()
getInvoices method failing
Getting "error": "Internal Error" on Postman and getting error Can not deserialize instance of java.util.ArrayList out of START_OBJECT token

Yodlee executeUserSearchRequest error

I try to get information from Yodlee API.
I have a test user where I've implemented adding an account and I got refresh OK from the site:
{ siteRefreshStatus: {
siteRefreshStatusId: 8
siteRefreshStatus: "REFRESH_COMPLETED_WITH_UNCERTAIN_ACCOUNT"
}
- siteRefreshMode: {
refreshModeId: 2
refreshMode: "NORMAL"
}
- updateInitTime: 0
nextUpdate: 1391603301
code: 403
noOfRetry: 0
}
}
Now when I try to perform search and get the actual transactions I get this error:
{
errorOccured: "true"
exceptionType: "com.yodlee.core.IllegalArgumentValueException"
refrenceCode: "_57c250a9-71e8-4d4b-830d-0f51a4811516"
message: "Invalid argument value: Container type cannot be null"
}
The problem is that I have container type!
Check out the parameters I send:
cobSessionToken=08062013_2%3Ad02590d4474591e507129bf6baaa58e81cd9eaacb5753e9441cd0b1ca3b8bd00a3e6b6a943956e947458307c1bb94b505e2eb4398f890040a3db8c98606c0392&userSessionToken=08062013_0%3A8e8ef9dd4f294e0f16dedf98c1794b96bf33f2e1f2686eda2f35dfe4901dd3a871eed6d08ce52c99a74deb004c025ebf4bf94c7b17baf8ba18aacb331588f5f5&transactionSearchRequest.containerType=bank&transactionSearchRequest.higherFetchLimit=1000&transactionSearchRequest.lowerFetchLimit=1&transactionSearchRequest.resultRange.endNumber=500&transactionSearchRequest.resultRange.startNumber=1&transactionSearchRequest.searchClients.clientId=1&transactionSearchRequest.searchClients.clientName=DataSearchService&transactionSearchRequest.ignoreUserInput=true&transactionSearchRequest.searchFilter.currencyCode=USD&transactionSearchRequest.searchFilter.postDateRange.fromDate=01-01-2014&transactionSearchRequest.searchFilter.postDateRange.toDate=01-31-2014&transactionSearchRequest.searchFilter+.transactionSplitType=ALL_TRANSACTION&transactionSearchRequest.searchFilter.itemAccountId+.identifier=10008425&transactionSearchRequest.searchClients=DEFAULT_SERVICE_CLIENT
There is an error occurred while adding the account, which can be interpreted by this parameter code: 403 and hence you will not be seeing that account when you call the getItemSummary API. An account is successfully linked if the code has zero as value. E.g.code:0 . 403 is an error which is show if Yodlee's data agent has encountered an unhandled use case. Hence for any such error you should file a service request using Yodlee customer care tool.
To know more about error codes please visit -
https://developer.yodlee.com/FAQs/Error_Codes
The status is show as completedsiteRefreshStatus: "REFRESH_COMPLETED_WITH_UNCERTAIN_ACCOUNT"because addition of any account is followed by a refresh in which Yodlee's data agent logs into the websites of FIs and try scraping data. Hence completion of this activity is denoted as REFRESH_COMPLETED even when there is an error occurred.
TranasctionSearch issue -
I can see two of the parameters with a "+" sign. Since transactionSlipttype and containerType are dependent on each other the error is thrown.
&transactionSearchRequest.searchFilter+.transactionSplitType=ALL_TRANSACTION
&transactionSearchRequest.searchFilter.itemAccountId+.identifier=10008425
The right parameters are -
&transactionSearchRequest.searchFilter.transactionSplitType=ALL_TRANSACTION
&transactionSearchRequest.searchFilter.itemAccountId.identifier=10008425