Yahoo Finance API Problems - urllib2

My code was working fine a few days ago but since Friday, I have been getting the following error:
File "C:\Python27\Lib\urllib2.py", line 527, in http_error_default
raise HTTPError(req.get_full_url(), code, msg, hdrs, fp)
urllib2.HTTPError: HTTP Error 500: Server Error
All I'm doing is accessing the historical data from the API. Is anyone else having this problem? Is the problem actually on the Yahoo servers? Is there a possibility that I'm sending too many requests (asking for historical data of 100 stocks)?

I am also having the same issue. I am using this query:
https://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20yahoo.finance.quote%20where%20symbol%20in%20(%22APPL%22)&format=json&diagnostics=true&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys&callback=
I am using
> Try
>
> objWebRequest = CType(System.Net.WebRequest.Create(strScrapeString),
> System.Net.HttpWebRequest)
> objWebRequest.KeepAlive = False
> objWebRequest.Method = "GET"
> **objWebResponse = CType(objWebRequest.GetResponse(), System.Net.HttpWebResponse)** *(this is where it fails on debug)*
>
>
> ...
>
> objWebResponse.Close()
>
>
> Return strStockPrice
>
> Catch ex As Exception
> strResults = strResults + "<br/>" + "**ERROR**" + strSymbol + " Yahoo data not available. Exception Error Message : " +
> ex.Message.ToString()
> End Try
I can see that I am getting the
The remote server returned an error: (500) Internal Server Error
on some stocks, but it isn't always the same ones. I am getting stock prices for about 40 stocks at a time.
Yahoo Finance has a limit of 2000 requests per hour for this query and if you exceed that it should error out with 403 error, so I do not think overuse is the cause of the 500 error. I am using a Try, Catch in my code around the objWebRequest.GetResponse.

Related

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

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

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

Unhandled exception when using VB arithmetic operators

I have a function that loops through a list of servers, and then for each carries out a number of functions.
At the beginning each iteration, I need to calculate which 'step' the process is currently at (so that a progress bar can be updated correctly), but this line is causing an error -
Me.CurrentStepLoop = ((Me.CurrentServerLoop - 1) * Me.ServerSteps) + 1
All three of the referenced properties are integers, and the values are quite low (I.e CurrentServerLoop has a maximum of 6 and ServerSteps has a maximum of 20, soCurrentStepLoop can be no more that 101 from this equation.
Here is the error that I am getting -
An unhandled exception of type 'System.Reflection.TargetInvocationException' occurred in mscorlib.dll
Additional information: Exception has been thrown by the target of an invocation.
I find it particularly odd that I have the line in question within a Try...Catch, yet the error is not handled by my code and instead I see generic Visual Exchange error. The line is not actually highlighted, but I know it is that as if I comment it out the error does not occur
Can anybody shed some light on why this may be happening? Thanks.
Here is the snippit that I believe is causing the issue, as well as a link to the full code -
For Each CurrentServer In Me.Servers
If bw.CancellationPending = True Then
e.Cancel = True
Exit For
Else
Try
Me.CurrentStepLoop = ((Me.CurrentServerLoop - 1) * Me.ServerSteps) + 1
Catch Ex As Exception
Dim ErrorForm As New formError(Ex)
e.Cancel = True
Exit For
End Try
MappingResult = Me.DoMapDrives(CurrentServer)
If Not MappingResult Then bw.CancelAsync() : Exit For
{...Other actions here...}
CurrentServerLoop += 1
End If
Next
I have found the error and why it occurred.
In the method SetSteps() I calculate Me.StepSize, but I was doing so incorrectly. Changing this -
Me.StepSize = Me.proProgress.Maximum / Me.ServerSteps
To this solved the problem -
Me.StepSize = Me.proProgress.Maximum / Me.TotalSteps
The issue was that the Progress bar was being set passed it's maximum, which caused the error. Thanks.

HTTPSConnectionPool Max retries exceeded

I've got a django app in production running on nginx/uwsgi. We recently started using SSL for all our connections. Since moving to SSL, I often get the following message:
HTTPSConnectionPool(host='foobar.com', port=443):
Max retries exceeded with url: /foo/bar
Essentially what happens is I've got the browser communicating with django server code, which then uses the requests library to call an api. Its the connection to the api that generates the error. Also, I've moved all our requests into one session (a requests session, that is), but this hasn't helped.
I've bumped up the number of uwsgi listeners since I thought that could be the problem, but our load isn't that high. Also, we never had this problem before SSL. Does anyone have some advice as to how to solve this problem?
Edit
Code snippet of how I call the API. I've posted it (mostly) verbatim. Note its not the code that actually fails, but the requests library that throws an exception when calling self.session.post
def save_answer(self):
logger.info("Saving answer to question")
url = "%s1.0/exam/learneranswer/" % self.api_url
response = {'success': False}
data = {'questionorder': self.request.POST.get('questionorder'),
'paper': self.request.POST.get('paper')}
data['answer'] = ",".join(self.request.POST.getlist('answer'))
r = self.session.post(url, data=simplejson.dumps(data))
if r.status_code == 201:
logger.info("Answer saved successfully")
response['success'] = True
elif r.status_code == 400:
if r.text == "Paper expired":
logger.warning("Timer has expired")
response['message'] = 'Your time has run out'
if r.text == "Question locked":
response['message'] = \
'This question is locked and cannot be answered anymore'
else:
logger.error("Unknown error")
self.log_error(r, "Unknown Error while saving answer")
else:
logger.error("Internal error")
self.log_error(r, "Internal error in api while saving answer")
return simplejson.dumps(response)
I've found that this error happens when some item in one of my views throws an exception. For example, when using the django 'requests' framework to post data to another URL:
r = requests.post(url, data=json.dumps(payload), headers=headers, timeout=5)
The downrange server was having connection issues, which threw an exception and that bubbled up and gave me the error you had above. I replaced with this:
try:
r = requests.post(url, data=json.dumps(payload), headers=headers, timeout=5)
except requests.exceptions.ConnectionError as e:
r = "No response"
And that fixed it (of course, I'd suggest adding in more error handling, but the above is the relevant subset).
You must disable validation like this
requests.get('https://google.com', verify=False)
You should specify your CA.
This Error occurs as a result of python script trying to connect to IBM service even before your wifi or ethernet connection is established. Have a try/catch to rectify or if trying to run as service then run service after network is established.

RunTime Error 380 - Specified Fieldname not found in object

I am running a VB6 application with a Pervasive V9.5 Database. I am receiving a RunTime Error 380 - Specified Fieldname not found in object when only 2 of my users are trying to log in. Rest of the office is fine...Does anyone have any idea what the issue could be? I have searched for a few hours now and can't find anything helpful.
The login uses a VAccess control during the login. Could this be caused by a missing DLL or OCX file on the client machine?
Any suggestions would be appreciated as I am out of ideas.
Edit:
With vaLogon
.RefreshLocations = True
.DdfPath = DataPath
.TableName = "USERLOG"
.Location = "USERLOG.MKD"
.Open
If .Status <> 0 Then
ErrMsg = "Error Opening File " + .TableName + " - Status " + str$(.Status) + vbCrLf + "Contact IT Department"
End If
End With
I have enabled VADebug mode and on the workstation in question, when the app is launched I receive the DDF error:
The VAccess control was unable to open FIELD.DDF at the specified DDFpath. This may result from an error in the DDFPath or refreshlocations properties, or from a corrupt FIELD.DDF.
Then an error message:
ACBtr732 - Btrieve status = 170, Brtrieve Opertation Code = 0, VAccessName = vaLogon, VALocation =
Then my login prompts for username and password and once the Login button is clicked is when the user receives the 380 Runtime.
The error 170 means "Database login required. Authentication to the database failed due to a wrong or missing username." Are you sure the Datapath variable has the proper path in it?
Can you connect to the database through the Pervasive Control Center? Does it require a user/password?
A corrupt DDF on the server would typically affect all users.