How to fix http.client.IncompleteRead error while dumping database on remote server

92 Views Asked by At

I have a python script that creates Odoo database dump and saves it to selected path on local computer. Script works like a charm when I am creating DB dump of local Odoo DB (localhost). But when I try to do the same with Odoo on remote server the dump always fail with http.client.IncompleteRead: IncompleteRead(288281040 bytes read) (byte value changes and is not 0 in most cases). I also have to mention that the size of DB is around 700MB (So its not exactly small file).

Here is the method that does the DB dump:

def download_db(odoo_connection, file_name_with_path):
    MAXIMUM_NUMBER_OF_ATTEMPTS = 2
    db_conn = xmlrpc.client.ServerProxy(odoo_connection.url + "/xmlrpc/db")
    for x in range(1, MAXIMUM_NUMBER_OF_ATTEMPTS + 1):
        print(
            f"Started database {odoo_connection.db} dump attempt number {x}/{MAXIMUM_NUMBER_OF_ATTEMPTS}..."
        )
        try:
            with open(file_name_with_path, "wb") as backup_file:
                decode = base64.b64decode(
                    db_conn.dump(
                        odoo_connection.master_password, odoo_connection.db, "zip"
                    )
                )
                backup_file.write(decode)
            print(f"Finished dumping {odoo_connection.db} \U0001F4A9 \U0001F4A9")
        except Exception as ex:
            traceback.print_exception(type(ex), ex, ex.__traceback__)
            print(f"Dumping database failed!")
            print(f"Retrying")

Error traceback:

Traceback (most recent call last):
  File "C:\Users\random_user\AppData\Local\Programs\Python\Python39\lib\http\client.py", line 555, in _get_chunk_left
    chunk_left = self._read_next_chunk_size()
  File "C:\Users\random_user\AppData\Local\Programs\Python\Python39\lib\http\client.py", line 522, in _read_next_chunk_size
    return int(line, 16)
ValueError: invalid literal for int() with base 16: b''

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\random_user\Desktop\CodingProjects\odoo_backup_script\odoo_backup_script.py", line 58, in download_db
    db_conn.dump(
  File "C:\Users\random_user\AppData\Local\Programs\Python\Python39\lib\xmlrpc\client.py", line 1116, in __call__
    return self.__send(self.__name, args)
  File "C:\Users\random_user\AppData\Local\Programs\Python\Python39\lib\xmlrpc\client.py", line 1456, in __request
    response = self.__transport.request(
  File "C:\Users\random_user\AppData\Local\Programs\Python\Python39\lib\xmlrpc\client.py", line 1160, in request
    return self.single_request(host, handler, request_body, verbose)
  File "C:\Users\random_user\AppData\Local\Programs\Python\Python39\lib\xmlrpc\client.py", line 1176, in single_request
    return self.parse_response(resp)
  File "C:\Users\random_user\AppData\Local\Programs\Python\Python39\lib\xmlrpc\client.py", line 1328, in parse_response
    stream = GzipDecodedResponse(response)
  File "C:\Users\random_user\AppData\Local\Programs\Python\Python39\lib\xmlrpc\client.py", line 1094, in __init__
    self.io = BytesIO(response.read())
  File "C:\Users\random_user\AppData\Local\Programs\Python\Python39\lib\http\client.py", line 465, in read
    return self._readall_chunked()
  File "C:\Users\random_user\AppData\Local\Programs\Python\Python39\lib\http\client.py", line 579, in _readall_chunked
    raise IncompleteRead(b''.join(value))
http.client.IncompleteRead: IncompleteRead(242873092 bytes read)

A brief Google search showed that it might be because unstable internet connection so I tried to retry the dump in case it failed (Even though my internet connection is very good), but even this way the dump never finished.

(Manual backup through Odoo UI works fine)

Please help me. I am more than happy to provide more information if necessary.

0

There are 0 best solutions below