Missing function for offline plots in python

Hey everybody,

I tried to get a image of a bar chart using only plotly offline without anyy results. After ours of trying I’m quite sure the I found the reason why this isn’t working (just to get an image “by code” isn’t possible, a normal offline plot of the same data is possible).

Executing the sample from https://plot.ly/python/static-image-export/ I first got this error message:

Traceback (most recent call last):
File “/usr/local/lib/python3.4/dist-packages/plotly/plotly/plotly.py”, line 703, in get
return_data = json.loads(res.content)
File “/usr/lib/python3.4/json/init.py”, line 312, in loads
s.class.name))
TypeError: the JSON object must be str, not ‘bytes’

During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File “barcharttest2.py”, line 42, in
py.image.save_as(fig, ‘/home/pi/plotlytest/test.png’)
File “/usr/local/lib/python3.4/dist-packages/plotly/plotly/plotly.py”, line 787, in save_as
img = cls.get(figure_or_data, format, width, height, scale)
File “/usr/local/lib/python3.4/dist-packages/plotly/plotly/plotly.py”, line 707, in get
raise exceptions.PlotlyError("The response "
plotly.exceptions.PlotlyError: The response from plotly could not be translated.

After Searching the Internet and especially github I copied the relevant code out of the libraries and tried to save an image manually. And so I got this error displayed:

Traceback (most recent call last):
File “barcharttest2.py”, line 27, in
img = cls.get(fig, format, width, height, scale)
AttributeError: type object ‘PlotlyJSONEncoder’ has no attribute ‘get’

I checked the code for the missing get but can’t find it.

Could someone please help me to find a solution for my problem or in case this is really a bug in plotly offline (advise to) fix this?

Greetings
Tim

Hi, just to make sure, are you removing the py.sign_in line, or replacing it with your own credentials?

I am not sure if this applies to your situation, but I am using the free version of Plotly (i.e. not a Pro user). I got this exact same error when trying to plot 20 different plots at once. It worked great for the first couple runs, but I needed to tweak some aesthetics of the output images, and the last time I tried to run my script, this exact error came up:
line 787, in save_as img = cls.get(figure_or_data, format, width, height, scale)
followed by:
PlotlyError("The response "
plotly.exceptions.PlotlyError: The response from plotly could not be translated.

After much searching to find errors in my script, I came up short. But then I came across some info about free Plotly accounts. Apparently free accounts are allowed no more than 50 API calls per day, or no more than 30 per hour. Thinking I might have overstepped the API calls allotted to my free account, I tried just making a second free account, to see if my theory was correct. Indeed my script ran perfectly using the newly created account, and output my 20 plot images just fine.

I wouldn’t call this a great solution, but more of an explanation that helped me not go insane, because I really couldn’t figure out why these errors were suddenly appearing, with no changes to my code.

I think I might be in for a Pro membership soon.

Hope that helped,
Nick