good night, I am testing a module to send the bbdd backup to google drive but this error appears to me. I think the error is in the json.dumps (for), but I don't identify why it might be happening. I would appreciate any help. release: odoo12
Traceback (most recent call last): File "/usr/lib/python3/dist-packages/odoo/tools/safe_eval.py", line 350, in safe_eval return unsafe_eval(c, globals_dict, locals_dict) File "", line 1, in <module> File "/mnt/extra-addons/auto_backup_upload/models/db_backup.py", line 174, in schedule_backup self.google_drive_upload(rec, file_path, bkp_file) File "/mnt/extra-addons/auto_backup_upload/models/db_backup.py", line 218, in google_drive_upload response = r.json() File "/usr/lib/python3/dist-packages/requests/models.py", line 850, in json return complexjson.loads(self.text, **kwargs) File "/usr/lib/python3.5/json/__init__.py", line 319, in loads return _default_decoder.decode(s) File "/usr/lib/python3.5/json/decoder.py", line 339, in decode obj, end = self.raw_decode(s, idx=_w(s, 0).end()) File "/usr/lib/python3.5/json/decoder.py", line 357, in raw_decode raise JSONDecodeError("Expecting value", s, err.value) from None json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0) During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/usr/lib/python3/dist-packages/odoo/http.py", line 654, in _handle_exception return super(JsonRequest, self)._handle_exception(exception) File "/usr/lib/python3/dist-packages/odoo/http.py", line 312, in _handle_exception raise pycompat.reraise(type(exception), exception, sys.exc_info()[2]) File "/usr/lib/python3/dist-packages/odoo/tools/pycompat.py", line 87, in reraise raise value File "/usr/lib/python3/dist-packages/odoo/http.py", line 696, in dispatch result = self._call_function(**self.params) File "/usr/lib/python3/dist-packages/odoo/http.py", line 344, in _call_function return checked_call(self.db, *args, **kwargs) File "/usr/lib/python3/dist-packages/odoo/service/model.py", line 97, in wrapper return f(dbname, *args, **kwargs) File "/usr/lib/python3/dist-packages/odoo/http.py", line 337, in checked_call result = self.endpoint(*a, **kw) File "/usr/lib/python3/dist-packages/odoo/http.py", line 939, in __call__ return self.method(*args, **kw) File "/usr/lib/python3/dist-packages/odoo/http.py", line 517, in response_wrap response = f(*args, **kw) File "/usr/lib/python3/dist-packages/odoo/addons/web/controllers/main.py", line 966, in call_button action = self._call_kw(model, method, args, {}) File "/usr/lib/python3/dist-packages/odoo/addons/web/controllers/main.py", line 954, in _call_kw return call_kw(request.env[model], method, args, kwargs) File "/usr/lib/python3/dist-packages/odoo/api.py", line 749, in call_kw return _call_kw_multi(method, model, args, kwargs) File "/usr/lib/python3/dist-packages/odoo/api.py", line 736, in _call_kw_multi result = method(recs, *args, **kwargs) File "/usr/lib/python3/dist-packages/odoo/addons/base/models/ir_cron.py", line 76, in method_direct_trigger self.sudo(user=cron.user_id.id).ir_actions_server_id.run() File "/usr/lib/python3/dist-packages/odoo/addons/base/models/ir_actions.py", line 565, in run res = func(action, eval_context=eval_context) File "/usr/lib/python3/dist-packages/odoo/addons/website/models/ir_actions.py", line 57, in run_action_code_multi res = super(ServerAction, self).run_action_code_multi(action, eval_context) File "/usr/lib/python3/dist-packages/odoo/addons/base/models/ir_actions.py", line 441, in run_action_code_multi safe_eval(action.sudo().code.strip(), eval_context, mode="exec", nocopy=True) # nocopy allows to return 'action' File "/usr/lib/python3/dist-packages/odoo/tools/safe_eval.py", line 373, in safe_eval pycompat.reraise(ValueError, ValueError('%s: "%s" while evaluating\n%r' % (ustr(type(e)), ustr(e), expr)), exc_info[2]) File "/usr/lib/python3/dist-packages/odoo/tools/pycompat.py", line 86, in reraise raise value.with_traceback(tb) File "/usr/lib/python3/dist-packages/odoo/tools/safe_eval.py", line 350, in safe_eval return unsafe_eval(c, globals_dict, locals_dict) File "", line 1, in <module> File "/mnt/extra-addons/auto_backup_upload/models/db_backup.py", line 174, in schedule_backup self.google_drive_upload(rec, file_path, bkp_file) File "/mnt/extra-addons/auto_backup_upload/models/db_backup.py", line 218, in google_drive_upload response = r.json() File "/usr/lib/python3/dist-packages/requests/models.py", line 850, in json return complexjson.loads(self.text, **kwargs) File "/usr/lib/python3.5/json/__init__.py", line 319, in loads return _default_decoder.decode(s) File "/usr/lib/python3.5/json/decoder.py", line 339, in decode obj, end = self.raw_decode(s, idx=_w(s, 0).end()) File "/usr/lib/python3.5/json/decoder.py", line 357, in raw_decode raise JSONDecodeError("Expecting value", s, err.value) from None ValueError: <class 'json.decoder.JSONDecodeError'>: "Expecting value: line 1 column 1 (char 0)" while evaluating 'model.schedule_backup()'
@api.model def schedule_backup(self): conf_ids = self.search([]) for rec in conf_ids: db_list = self.get_db_list(rec.host, rec.port) if rec.name in db_list: try: if not os.path.isdir(rec.folder): os.makedirs(rec.folder) except: raise # Create name for dumpfile. user_tz = pytz.timezone(self.env.context.get('tz') or self.env.user.tz) date_today = pytz.utc.localize(datetime.datetime.today()).astimezone(user_tz) bkp_file = '%s_%s.%s' % (rec.name,date_today.strftime('%Y-%m-%d_%H_%M_%S'), rec.backup_type) file_path = os.path.join(rec.folder, bkp_file) uri = 'http://' + rec.host + ':' + rec.port conn = xmlrpclib.ServerProxy(uri + '/xmlrpc/db') bkp = '' try: # try to backup database and write it away fp = open(file_path, 'wb') odoo.service.db.dump_db(rec.name, fp, rec.backup_type) fp.close() except Exception as error: _logger.debug( "Couldn't backup database %s. Bad database administrator password for server running at http://%s:%s" % ( rec.name, rec.host, rec.port)) _logger.debug("Exact error from the exception: " + str(error)) continue else: _logger.debug("database %s doesn't exist on http://%s:%s" % (rec.name, rec.host, rec.port)) """ Remove all old files (on local server) in case this is configured.. """ if rec.autoremove: dir = rec.folder # Loop over all files in the directory. for f in os.listdir(dir): fullpath = os.path.join(dir, f) # Only delete the ones wich are from the current database # (Makes it possible to save different databases in the same folder) if rec.name in fullpath: timestamp = os.stat(fullpath).st_ctime createtime = datetime.datetime.fromtimestamp(timestamp) now = datetime.datetime.now() delta = now - createtime if delta.days >= rec.days_to_keep: # Only delete files (which are .dump and .zip), no directories. if os.path.isfile(fullpath) and (".dump" in f or '.zip' in f): _logger.info("Delete local out-of-date file: " + fullpath) os.remove(fullpath) self.google_drive_upload(rec, file_path, bkp_file)
@api.multi def google_drive_upload(self, rec, file_path, bkp_file): g_drive = self.env['google.drive.config'] access_token = GoogleDrive.get_access_token(g_drive) # GOOGLE DRIVE UPLOAP if rec.is_upload: headers = {"Authorization": "Bearer %s" % (access_token)} para = { "name": "%s" % (str(bkp_file)), "parents": ["%s" % (str(rec.drive_folder_id))] } files = { 'data': ('metadata', json.dumps(para), 'application/json; charset=UTF-8'), 'file': open("%s" % (str(file_path)), "rb") } r = requests.post( "https://www.googleapis.com/upload/drive/v3/files?uploadType=multipart", headers=headers, files=files ) # SENDING EMAIL NOTIFICATION if r.status_code == 200: email_to = "" for record in rec.gdrive_email_notif_ids.mapped('login'): email_to += record + ',' notification_template = self.env['ir.model.data'].sudo().get_object('auto_backup_upload', 'email_google_drive_upload') values = notification_template.generate_email(self.id) values['email_from'] = self.env['res.users'].browse(self.env.uid).company_id.email values['email_to'] = email_to values['subject'] = "Google Drive Upload Successful" values['body_html'] = "<h3>Backup Successfully Uploaded!</h3>" \ "Please see below details. <br/> <br/> " \ "<b>Backup File: %s" % (str(bkp_file)) + \ " <a href='https://drive.google.com/drive/u/0/folders/%s'>Open</a></b>" % ( str(rec.drive_folder_id)) send_mail = self.env['mail.mail'].create(values) send_mail.send(True) else: response = r.json() code = response['error']['code'] message = response['error']['errors'][0]['message'] reason = response['error']['errors'][0]['reason'] email_to = "" for rec in rec.gdrive_email_notif_ids.mapped('login'): email_to += rec + ',' notification_template = self.env['ir.model.data'].sudo().get_object('auto_backup_upload', 'email_google_drive_upload') values = notification_template.generate_email(self.id) values['email_from'] = self.env['res.users'].browse(self.env.uid).company_id.email values['email_to'] = email_to values['subject'] = "Google Drive Upload Failed" values['body_html'] = "<h3>Backup Upload Failed!</h3>" \ "Please see below details. <br/> <br/> " \ "<table style='width:100%'>" \ "<tr> " \ "<th align='left'>Backup</th>" \ "<td>" + (str(bkp_file)) + "</td></tr>" \ "<tr> " \ "<th align='left'>Code</th>" \ "<td>" + str(code) + "</td>" \ "</tr>" \ "<tr>" \ "<th align='left'>Message</th>" \ "<td>" + str( message) + "</td>" \ "</tr>" \ "<tr>" \ "<th align='left'>Reason</th>" \ "<td>" + str(reason) + "</td>" \ "</tr> " \ "</table>" send_mail = self.env['mail.mail'].create(values) send_mail.send(True)