gdata internal error - python

Since yesterday a working Python gdata program has stopped working after I changed the IP address used.
I receive the following stack trace:
Traceback (most recent call last):
File "C:\prod\googleSite\googleSite2.py", line 23, in
feed = client.GetContentFeed()
File "C:\Python27\lib\site-packages\gdata\sites\client.py", line 155, in get_c
ontent_feed
auth_token=auth_token, **kwargs)
File "C:\Python27\lib\site-packages\gdata\client.py", line 635, in get_feed
**kwargs)
File "C:\Python27\lib\site-packages\gdata\client.py", line 320, in request
RequestError)
gdata.client.RequestError: Server responded with: 500, Internal Error
The code is as follow:
import gdata.sites.client
import gdata.sites.data
client = gdata.sites.client.SitesClient(source='xxx', site='yyy')
client.ssl = True # Force API requests through HTTPS
client.ClientLogin('user#googlemail.com', 'password', client.source);
feed = client.GetContentFeed();
Update:
The issue fixes itself after an hour - is there any kind of commit or logout to avoid this?

Since you're not passing anything in GetContentFeed, it's using CONTENT_FEED_TEMPLATE % (self.domain, self.site) as the URI. I'm not sure if the IP change had an impact on what the self.domain/self.site values should be, but it might be worth checking those out.

Related

werkzeug exception: ClientDisconnected: 400 Bad Request: The browser (or proxy) sent a request that this server could not understand

I am getting this error:
werkzeug.exceptions.ClientDisconnected: 400 Bad Request: The browser (or proxy) sent a request that this server could not understand.
Full stack below. Happening with Python 3.10.5 on an Ubuntu 18.04 VM. Using Werkzeug 2.1.2.
Any idea of the cause?
No problem on Windows 10 or an Ubuntu 18.04 NUC. Works fine on Ubuntu 18.04 VM with Python 3.6.5 and Werkzeug 1.0.1.
Traceback (most recent call last):
File "/usr/local/lib/python3.10/site-packages/werkzeug/wsgi.py", line 921, in read
read = self._read(to_read)
ValueError: read of closed file
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/local/lib/python3.10/site-packages/werkzeug/formparser.py", line 140, in wrapper
return f(self, stream, *args, **kwargs)
File "/usr/local/lib/python3.10/site-packages/werkzeug/formparser.py", line 290, in _parse_multipart
form, files = parser.parse(stream, boundary, content_length)
File "/usr/local/lib/python3.10/site-packages/werkzeug/formparser.py", line 418, in parse
for data in iterator:
File "/usr/local/lib/python3.10/site-packages/werkzeug/wsgi.py", line 653, in _make_chunk_iter
item = _read(buffer_size)
File "/usr/local/lib/python3.10/site-packages/werkzeug/wsgi.py", line 923, in read
return self.on_disconnect()
File "/usr/local/lib/python3.10/site-packages/werkzeug/wsgi.py", line 893, in on_disconnect
raise ClientDisconnected()
werkzeug.exceptions.ClientDisconnected: 400 Bad Request: The browser (or proxy) sent a request that this server could not understand.
It's just as it states, the client disconnected. The reason? could be several, they could have had a network problem, they could have clicked a different link, they could have navigated away. either way, the server could no longer talk to your client and finish the transfer of data.
It's the most annoying error in the world, you can't do anything about it.

Catching Firebase 504 gateway timeout

I'm building a simple IOT device (with a Raspberry Pi Zero) which pulls data from Firebase Realtime Database every 1 second and checks for updates.
However, after a certain time (not sure exactly how much but somewhere between 1 hour and 3 hours) the program exits with a 504 Server Error: Gateway Time-out message.
I couldn't understand exactly why this is happening, I tried to recreate this error by disconnecting the Pi from the internet and I did not get this message. Instead, the program simply paused in a ref.get() line and automatically resumed running once the connection was back.
This device is meant to be always on, so ideally if I get some kind of error, I would like to restart the program / reinitiate the connection / reboot the Pi. Is there a way to achieve something like this?
It seems like the message is actually generated by the firebase_admin package.
Here is the error message:
Traceback (most recent call last):
File "/home/pi/.local/lib/python3.7/site-packages/firebase_admin/db.py", line 944, in request
return super(_Client, self).request(method, url, **kwargs)
File "/home/pi/.local/lib/python3.7/site-packages/firebase_admin/_http_client.py", line 105, in request
resp.raise_for_status()
File "/usr/lib/python3/dist-packages/requests/models.py", line 940, in raise_for_status
raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 504 Server Error: Gateway Time-out for url: https://someFirebaseProject.firebaseio.com/someRef/subSomeRef/payload.json
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/pi/Desktop/project/main.py", line 94, in <module>
lastUpdate = ref.get()['lastUpdate']
File "/home/pi/.local/lib/python3.7/site-packages/firebase_admin/db.py", line 223, in get
return self._client.body('get', self._add_suffix(), params=params)
File "/home/pi/.local/lib/python3.7/site-packages/firebase_admin/_http_client.py", line 117, in body
resp = self.request(method, url, **kwargs)
File "/home/pi/.local/lib/python3.7/site-packages/firebase_admin/db.py", line 946, in request
raise _Client.handle_rtdb_error(error)
firebase_admin.exceptions.UnknownError: Internal server error.
>>>
To reboot the whole Raspberry Pi, you can just run a shell command:
import os
os.system("sudo reboot")
I've had this problem too and usually feel safer with that, but there's obvious downsides. I'd try resetting the wifi connection or network interface in a similar way

Timeout error when uploading video to Vimeo through their API

I have a Python script that takes advantage of the latest Vimeo API (https://developer.vimeo.com/api/) to upload some videos to my Vimeo account.
Here is what, in a slightly simplified form, the script basically does:
from vimeo import VimeoClient
vimeo = VimeoClient('my_token_here')
uid = vimeo.upload('/path/to/file.mov')
When file.mov is 3MB or less everything works fine and the file is successfully uploaded. However, for larger files I get a timeout error:
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "/home/fabio/.virtualenvs/venv/src/vimeo/vimeo/uploads.py", line 79, in __call__
return do_upload()
File "/home/fabio/.virtualenvs/venv/src/vimeo/vimeo/uploads.py", line 70, in do_upload
self.upload_segment(upload_uri, _range, video_data, filetype or 'mp4')
File "/home/fabio/.virtualenvs/venv/src/vimeo/vimeo/uploads.py", line 135, in upload_segment
body=data, headers=request_headers)
File "/home/fabio/.virtualenvs/venv/lib/python2.7/site-packages/tornado/httpclient.py", line 85, in fetch
self._async_client.fetch, request, **kwargs))
File "/home/fabio/.virtualenvs/venv/lib/python2.7/site-packages/tornado/ioloop.py", line 389, in run_sync
return future_cell[0].result()
File "/home/fabio/.virtualenvs/venv/lib/python2.7/site-packages/tornado/concurrent.py", line 131, in result
return super(TracebackFuture, self).result(timeout=timeout)
File "/home/fabio/.virtualenvs/venv/lib/python2.7/site-packages/tornado/concurrent.py", line 65, in result
raise self._exception
HTTPError: HTTP 599: Timeout
This is the vimeo library I am using: https://github.com/vimeo/vimeo.py.
And the Tornado library in my virtual environment is updated to the 3.2.1 version.
Any tips for me?
From the Tornado source, the default request timeout for an HTTPClient which vimeo is using is 20 seconds. It looks like the Vimeo library attempts to upload as much of the video as possible, and then queries the server to see how much was successfully uploaded. It is likely that it is taking over 20 seconds to upload your video and as a result timing out. I'm not convinced they handle this properly though, as you get a timeout error from Tornado, but it seems like they want to support the whole file not being uploaded at once.
You could try modifying the vimeo library code that I linked above to have a much longer timeout by changing the linked line in your local copy to something like:
r = HTTPClient().fetch(upload_uri, method="PUT",
body=data, headers=request_headers,
request_timeout=9999.0)
If that doesn't work you could try raising an issue on their github issues tracker, and someone who actually works on the project might be able to help you further.

Timeout problems with the Riak Python Client with protocol buffers

I'm seeing a strange but consistent behaviour from the Python Riak Client when connecting to my riak AWS cluster using protocol buffers. This short python snippet produces the error:
import time
import riak
client = riak.RiakClient(
host='address_to_my_cluster_goes_here',
http_port=8098,
pb_port=8087,
protocol='pbc'
)
result = client.ping()
# Do something else for a while, > 60 seconds
time.sleep(61)
result = client.ping()
The last ping always throws an exception, with the following traceback:
Traceback (most recent call last):
File "main_causing_exception.py", line 16, in <module>
result = client.ping()
File "C:\temp\venv\lib\site-packages\riak\client\transport.py", line 127, in wrapper
return self._with_retries(pool, thunk)
File "C:\temp\venv\lib\site-packages\riak\client\transport.py", line 69, in _with_retries
return fn(transport)
File "C:\temp\venv\lib\site-packages\riak\client\transport.py", line 125, in thunk
return fn(self, transport, *args, **kwargs)
File "C:\temp\venv\lib\site-packages\riak\client\operations.py", line 92, in ping
return transport.ping()
File "C:\temp\venv\lib\site-packages\riak\transports\pbc\transport.py", line 95, in ping
msg_code, msg = self._request(MSG_CODE_PING_REQ)
File "C:\temp\venv\lib\site-packages\riak\transports\pbc\connection.py", line 43, in _request
return self._recv_msg(expect)
File "C:\temp\venv\lib\site-packages\riak\transports\pbc\connection.py", line 50, in _recv_msg
self._recv_pkt()
File "C:\temp\venv\lib\site-packages\riak\transports\pbc\connection.py", line 71, in _recv_pkt
% len(nmsglen))
riak.RiakError: 'Socket returned short packet length 0 - expected 4'
If I do the client.ping() every 30 seconds or so, the error doesn't happen, indicating that it's some kind of socket keep-alive problem I'm seeing, but this does't seem like a solution robust enough for a production environment.
The error only occurs when using the pbc protocol setting and I've never seen it when using a http configured Riak Python Client.
I'm using Python 2.7.5 on a Win7-64 platform (though the error also occurs on our Ubuntu development server) in a virtual environment with the following packages and versions:
protobuf (2.4.1)
riak (2.0.1)
riak-pb (1.4.1.1)
Any thoughts on what's going on and how to resolve it? Am I using the Python Riak Client in the wrong way?
You should use a newer version of Riak library.
There was an error with send function in PBC transport, that was resolved here: https://github.com/basho/riak-python-client/issues/381

prestapyt error on edit

I'm using the prestashop API prestapyt
I add a category by hand in my site, but when I'm trying to edit via the API, it fails.
Even the most simple thing, does not work:
ps = PrestaShopWebServiceDict(config.DOMAIN, config.KEY)
xml = ps.get('categories', 35)
ps.edit('categories',35,xml)
The xml (type DICT) loads ok, but the .edit() fails.
Here is the response
Traceback (most recent call last):
File "C:\Users\noukeys\Documents\psapi\main.py", line 31, in <module>
ps.edit('categories',35,xml)
File "C:\Python27\lib\site-packages\prestapyt\prestapyt.py", line 333, in edit
return self.edit_with_url(full_url, content)
File "C:\Python27\lib\site-packages\prestapyt\prestapyt.py", line 452, in edit_with_url
return super(PrestaShopWebServiceDict, self).edit_with_url(url, xml_content)
File "C:\Python27\lib\site-packages\prestapyt\prestapyt.py", line 344, in edit_with_url
return self._parse(self._execute(url, 'PUT', body=unicode_encode.encode(content), add_headers=headers)[2])
File "C:\Python27\lib\site-packages\prestapyt\prestapyt.py", line 171, in _execute
self._check_status_code(status_code)
File "C:\Python27\lib\site-packages\prestapyt\prestapyt.py", line 125, in _check_status_code
% (status_code, message_by_code[status_code]), status_code)
prestapyt.prestapyt.PrestaShopWebServiceError: 'This call to PrestaShop Web Services failed and returned an HTTP status of 400. That means: Bad Request.'
I'm having issues with edits also, but I am getting a 501 error. Turns out my host does not allow PUT requests.
You can turn on debugging in the api.
prestashop.debug = True
And then turn on display_errors in config.inc.php for your shop. This helped me debug why the request was bad. The error messages are pretty clear.

Categories