Python Forum
Get return text from a failed script
Thread Rating:
  • 4 Vote(s) - 3 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Get return text from a failed script
#1
Hi,

I'm new to Python and I'm trying to run a their script.  It works a treat, however, if I use it too much, I get an error saying I've breached the API limit.

Is there a way I can somehow capture that text response?  I'll include the last bit of my script.  The error gets generated at the very last line.

layout = go.Layout(
title='BigScenario - Average',
xaxis=dict(
title='Application Version',
titlefont=dict(
family='Times New Roman, monospace',
size=18
)
),
yaxis=dict(
title='Seconds',
titlefont=dict(
family='Times New Roman, monospace',
size=18
)
),
hovermode='closest'
)

fig = go.Figure(data=data, layout=layout)
plot_url = py.plot(fig, filename='09052017230558')
So when I run it, I get the following returned in the console:
   
Error:
plot_url = py.plot(fig, filename='09052017230558')   File "C:\Users\John\AppData\Local\Programs\Python\Python36\lib\site-packages\plotly\plotly\plotly.py", line 227, in plot     response = v1.clientresp(data, **plot_options)   File "C:\Users\John\AppData\Local\Programs\Python\Python36\lib\site-packages\plotly\api\v1\clientresp.py", line 35, in clientresp     response = request('post', url, data=payload)   File "C:\Users\John\AppData\Local\Programs\Python\Python36\lib\site-packages\plotly\api\v1\utils.py", line 86, in request     validate_response(response)   File "C:\Users\John\AppData\Local\Programs\Python\Python36\lib\site-packages\plotly\api\v1\utils.py", line 38, in validate_response     raise exceptions.PlotlyRequestError(message, status_code, content) plotly.exceptions.PlotlyRequestError: Hey there! You've hit one of our API request limits.  To get unlimited API calls(10,000/day), please upgrade to a paid plan.  Thanks for using Plotly! Happy Plotting!
I'd like to capture and check for a substring in that error if it occurs.  Is this possible?

Many thanks,
J
Reply
#2
from plotly.exceptions import PlotlyRequestError

try:
   plot_url = py.plot(fig, filename='09052017230558')
except PlotlyRequestError:
   # here you can do what you want when this error is raised
   # to handle it graciously e.g.
   print("Hey there! You've hit one of our API request limits.")
you need to use try/except block. Note that you need to import the specific error (at the top of the script). i.e. you don't check for the string - that's how exceptions are handled in python.
Also in the above example I just print the message, but if you reached the limit, maybe it's better to quit or whatever else you deem necessary.
Reply
#3
Hi mate,

Many thanks for that!  It has worked a treat.

I'll read up some more on that but a good start.

Cheers,
John
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Script that alternates between 2 text messages DiscoMatic 1 1,250 Dec-12-2023, 03:02 PM
Last Post: buran
  Python script that deletes symbols in plain text nzcan 3 1,657 Sep-05-2023, 04:03 PM
Last Post: deanhystad
  Receiving this error in my "response" and causes script to return wrong status cubangt 18 5,293 Aug-13-2023, 12:16 AM
Last Post: cubangt
  [split] script: remove all "carriage return" from my json variable pete 2 3,953 May-05-2020, 03:22 PM
Last Post: deanhystad
  Simple text to binary python script gmills13 2 4,067 Feb-04-2020, 08:44 PM
Last Post: snippsat
  index error in text script Bartry 2 3,136 Dec-09-2019, 11:50 AM
Last Post: Malt
  auto supply values to a python script(function) from text file metro17 4 3,571 Oct-26-2019, 01:25 AM
Last Post: ichabod801
  Pyinstaller with Sys.Argv[] - “Failed to Execute Script”? ironfelix717 0 6,209 Aug-07-2019, 02:29 PM
Last Post: ironfelix717
  Help with PyInstaller + Script "Failed to Execute Script" ironfelix717 2 10,503 Jul-31-2019, 02:18 PM
Last Post: ironfelix717
  script: remove all "carriage return" from my json variable mfran2002 4 13,649 Feb-20-2019, 05:07 AM
Last Post: mfran2002

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020