mail-in-a-box / mailinabox

Mail-in-a-Box helps individuals take back control of their email by defining a one-click, easy-to-deploy SMTP+everything else server: a mail server in a box.
https://mailinabox.email/
Creative Commons Zero v1.0 Universal
13.89k stars 1.43k forks source link

I get a 500 Internal Server Error when I try to set up a service compatible with S3. #2266

Closed horyu1234 closed 1 year ago

horyu1234 commented 1 year ago

mail-in-a-box version: v62 compatible with S3 service: Cloudflare R2

When I click the Save Settings button, a message is displayed stating that an internal server error has occurred.

Backup Setting

image

Error Screen

image

Error Log (/var/log/syslog)

May 24 01:56:49 box start[1865]: [2023-05-24 01:56:49,348] ERROR in app: Exception on /system/backup/config [POST]
May 24 01:56:49 box start[1865]: Traceback (most recent call last):
May 24 01:56:49 box start[1865]:   File "/usr/local/lib/mailinabox/env/lib/python3.10/site-packages/flask/app.py", line 2190, in wsgi_app
May 24 01:56:49 box start[1865]:     response = self.full_dispatch_request()
May 24 01:56:49 box start[1865]:   File "/usr/local/lib/mailinabox/env/lib/python3.10/site-packages/flask/app.py", line 1486, in full_dispatch_request
May 24 01:56:49 box start[1865]:     rv = self.handle_user_exception(e)
May 24 01:56:49 box start[1865]:   File "/usr/local/lib/mailinabox/env/lib/python3.10/site-packages/flask/app.py", line 1484, in full_dispatch_request
May 24 01:56:49 box start[1865]:     rv = self.dispatch_request()
May 24 01:56:49 box start[1865]:   File "/usr/local/lib/mailinabox/env/lib/python3.10/site-packages/flask/app.py", line 1469, in dispatch_request
May 24 01:56:49 box start[1865]:     return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args)
May 24 01:56:49 box start[1865]:   File "/root/mailinabox/management/daemon.py", line 75, in newview
May 24 01:56:49 box start[1865]:     return viewfunc(*args, **kwargs)
May 24 01:56:49 box start[1865]:   File "/root/mailinabox/management/daemon.py", line 635, in backup_set_custom
May 24 01:56:49 box start[1865]:     return json_response(backup_set_custom(env,
May 24 01:56:49 box start[1865]:   File "/root/mailinabox/management/backup.py", line 543, in backup_set_custom
May 24 01:56:49 box start[1865]:     list_target_files(config)
May 24 01:56:49 box start[1865]:   File "/root/mailinabox/management/backup.py", line 499, in list_target_files
May 24 01:56:49 box start[1865]:     bucket_objects = s3.list_objects_v2(Bucket=bucket, Prefix=path)['Contents']
May 24 01:56:49 box start[1865]: KeyError: 'Contents'
May 24 01:56:49 box Exception on /system/backup/config [POST]#012Traceback (most recent call last):#012  File "/usr/local/lib/mailinabox/env/lib/python3.10/site-packages/flask/app.py", line 2190, in wsgi_app#012    response = self.full_dispatch_request()#012  File "/usr/local/lib/mailinabox/env/lib/python3.10/site-packages/flask/app.py", line 1486, in full_dispatch_request#012    rv = self.handle_user_exception(e)#012  File "/usr/local/lib/mailinabox/env/lib/python3.10/site-packages/flask/app.py", line 1484, in full_dispatch_request#012    rv = self.dispatch_request()#012  File "/usr/local/lib/mailinabox/env/lib/python3.10/site-packages/flask/app.py", line 1469, in dispatch_request#012    return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args)#012  File "/root/mailinabox/management/daemon.py", line 75, in newview#012    return viewfunc(*args, **kwargs)#012  File "/root/mailinabox/management/daemon.py", line 635, in backup_set_custom#012    return json_response(backup_set_custom(env,#012  File "/root/mailinabox/management/backup.py", line 543, in backup_set_custom#012    list_target_files(config)#012  File "/root/mailinabox/management/backup.py", line 499, in list_target_files#012    bucket_objects = s3.list_objects_v2(Bucket=bucket, Prefix=path)['Contents']#012KeyError: 'Contents'
horyu1234 commented 1 year ago

Cloudflare R2 screen

image

image

volkv commented 1 year ago

Try to remove https:// from r2 host and make sure your backup folder exists

horyu1234 commented 1 year ago

Issue resolved, closed.

The cause was a problem that occurred because the path folder to be backed up was not created in R2.

I thought the folder would be created automatically, but it wasn't.

nomandera commented 7 months ago

Further potentially useful info when landing here via google.

I came across this issue whilst testing with minio.

minio users are used to placing a trailing / at the end of the prefix to signify creating a new folder but mailinabox complains about illegal characters if you do this. Simple remove it i.e. bucket/newfolder/ becomes bucket/newfolder .