Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

With https turned on verbose > 3 wsgidav fs_dav_provider crashes with AttributeError: 'int' object has no attribute 'encode' #198

Closed
rovitotv opened this issue Dec 11, 2020 · 1 comment

Comments

@rovitotv
Copy link

Using WsgiDAV/3.0.5-a3 Python/3.8.0 Linux-5.4.0-1030-gcp-x86_64-with-glibc2.27

This bug is similar to #189 but I tried including "'error_printer': {'catch_all': True}" and the crash still happened. Thank you for your help!

Code used from a wsgidav server.py example.

from cheroot import wsgi
from cheroot.ssl.builtin import BuiltinSSLAdapter
import ssl
from wsgidav.wsgidav_app import WsgiDAVApp
from fs_dav_provider import FilesystemProvider
import logging


config = {
    'add_header_MS_Author_Via': True,
 'dir_browser': {'davmount': False,
                 'enable': True,
                 'icon': True,
                 'ignore': ['.DS_Store', '._*', 'Thumbs.db'],
                 'ms_mount': False,
                 'ms_sharepoint_support': True,
                 'response_trailer': True,
                 'show_user': True,
                 'htdocs_path': '/home/rovitotv/code/NextVDL/htdocs/'},
 'enable_loggers': [],
 'error_printer': {'catch_all': True},
 'host': '0.0.0.0',
 'hotfixes': {'emulate_win32_lastmod': False,
              're_encode_path_info': None,
              'unquote_path_info': False,
              'win_accept_anonymous_options': False,
              'winxp_accept_root_share_login': False},
 'lock_manager': True,
 'mount_path': None,
 'mutable_live_props': [],
 'port': 8000,
 'property_manager': None,
 'provider_mapping': {'/dav': FilesystemProvider('/NextVDL/files', readonly=False),},
 'server': 'cheroot',
 'server_args': {},
        "simple_dc": {
        "user_mapping": {
            "*": True,
        },
    },
    # HTTP Authentication Options
    "http_authenticator": {
        # None: dc.simple_dc.SimpleDomainController(user_mapping)
        "domain_controller": None,
        "accept_basic": False,  # Allow basic authentication, True or False
        "accept_digest": False,  # Allow digest authentication, True or False
        "default_to_digest": False,  # True (default digest) or False (default basic)
        # Name of a header field that will be accepted as authorized user
        "trusted_auth_header": None,
    },
 'verbose': 6
}



logging.basicConfig(level=logging.DEBUG)
logger = logging.getLogger("wsgidav")
logger.propagate = True
logger.setLevel(logging.DEBUG)
app = WsgiDAVApp(config)
server_args = {
    "bind_addr": (config["host"], config["port"]),
    "wsgi_app": app,
    }
server = wsgi.Server(**server_args)
server.ssl_adapter = BuiltinSSLAdapter("/home/rovitotv/code/NextVDL/cert.pem", "/home/rovitotv/code/NextVDL/key.pem", None)
server.start()

The following output is produced:

INFO:wsgidav.wsgidav_app:WsgiDAV/3.0.5-a3 Python/3.8.0 Linux-5.4.0-1030-gcp-x86_64-with-glibc2.27
INFO:wsgidav.wsgidav_app:Default encoding: 'utf-8' (file system: 'utf-8')
INFO:wsgidav.wsgidav_app:Lock manager:      LockManager(LockStorageDict)
INFO:wsgidav.wsgidav_app:Property manager:  None
INFO:wsgidav.wsgidav_app:Domain controller: SimpleDomainController()
INFO:wsgidav.wsgidav_app:Middleware stack:
INFO:wsgidav.wsgidav_app:  - wsgidav.debug_filter.WsgiDavDebugFilter
INFO:wsgidav.wsgidav_app:  - wsgidav.error_printer.ErrorPrinter
INFO:wsgidav.wsgidav_app:  - wsgidav.http_authenticator.HTTPAuthenticator
INFO:wsgidav.wsgidav_app:  - wsgidav.dir_browser._dir_browser.WsgiDavDirBrowser
INFO:wsgidav.wsgidav_app:  - wsgidav.request_resolver.RequestResolver
INFO:wsgidav.wsgidav_app:Registered DAV providers by route:
INFO:wsgidav.wsgidav_app:  - '/:dir_browser': FilesystemProvider for path '/home/rovitotv/code/NextVDL/htdocs' (Read-Only) (anonymous)
INFO:wsgidav.wsgidav_app:  - '/dav': FilesystemProvider for path '/NextVDL/files' (Read-Write) (anonymous)
WARNING:wsgidav.wsgidav_app:Share '/dav' will allow anonymous write access.
WARNING:wsgidav.wsgidav_app:Share '/:dir_browser' will allow anonymous read access.





INFO:wsgidav.debug_filter:GET Request ---
INFO:wsgidav.debug_filter:ACTUAL_SERVER_PROTOCOL: 'HTTP/1.1'
INFO:wsgidav.debug_filter:PATH_INFO           : ''
INFO:wsgidav.debug_filter:QUERY_STRING        : ''
INFO:wsgidav.debug_filter:REMOTE_ADDR         : '98.29.120.87'
INFO:wsgidav.debug_filter:REMOTE_PORT         : '37892'
INFO:wsgidav.debug_filter:REQUEST_METHOD      : 'GET'
INFO:wsgidav.debug_filter:REQUEST_URI         : '/dav'
INFO:wsgidav.debug_filter:SCRIPT_NAME         : '/dav'
INFO:wsgidav.debug_filter:SERVER_NAME         : 'Cheroot/8.5.0'
INFO:wsgidav.debug_filter:SERVER_PROTOCOL     : 'HTTP/1.1'
INFO:wsgidav.debug_filter:SERVER_SOFTWARE     : 'Cheroot/8.5.0 Server'
INFO:wsgidav.debug_filter:SERVER_PORT         : '8000'
INFO:wsgidav.debug_filter:HTTP_HOST           : 'REMOVED ON PURPOSE'
INFO:wsgidav.debug_filter:HTTP_CONNECTION     : 'keep-alive'
INFO:wsgidav.debug_filter:HTTP_UPGRADE_INSECURE_REQUESTS: '1'
INFO:wsgidav.debug_filter:HTTP_USER_AGENT     : 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36'
INFO:wsgidav.debug_filter:HTTP_ACCEPT         : 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9'
INFO:wsgidav.debug_filter:HTTP_SEC_FETCH_SITE : 'same-site'
INFO:wsgidav.debug_filter:HTTP_SEC_FETCH_MODE : 'navigate'
INFO:wsgidav.debug_filter:HTTP_SEC_FETCH_DEST : 'iframe'
INFO:wsgidav.debug_filter:HTTP_REFERER        : 'REMOVED ON PURPOSE'
INFO:wsgidav.debug_filter:HTTP_ACCEPT_ENCODING: 'gzip, deflate, br'
INFO:wsgidav.debug_filter:HTTP_ACCEPT_LANGUAGE: 'en-US,en;q=0.9'
INFO:wsgidav.debug_filter:HTTP_COOKIE         : 'session=.eJx9kM1Kw0AYRd8la9vM_09BUFGEgpWqC12FLzPfNMEk0yaTLiq-uxMEl-7u4nDv4X4VVRhxaopNGme8KqrWF5sCUARQQhFHTK1oYEIbATxIUQepICfHTNDC1sQhellbrS0FJ4w0zBqhLYIQxASCDJkk1jHJKRgK0ghCHKslYUp4UhvI7Q65BCmZlj4gKlEXWWSecPy1oYRTY6nmhirCieZWcpWRY-vSPGI1j12mmpSO06Ysu4avDzEeOlwaXBwSDmntYl_Cqrx9bqh4bD_9EJ_sw9me-t3Kq3nXvn_cX7b7IfH96-Vut1XH15fryaqVyzvz0J5m_N9l2Zoq7KFdXFL0fj3Gc5viDSz_Ioyu6aBePP7oAXrM8FuGi-8fM-V3DA.X9Ob_A.aHejdw4Cluz9SAZb3Req6z7hVfk'
INFO:wsgidav.debug_filter:HTTPS               : 'on'
INFO:wsgidav.debug_filter:SSL_PROTOCOL        : 'TLSv1.3'
INFO:wsgidav.debug_filter:SSL_CIPHER          : 'TLS_AES_256_GCM_SHA384'
INFO:wsgidav.debug_filter:SSL_CIPHER_EXPORT   : ''
ValueError("invalid literal for int() with base 10: ''")
Traceback (most recent call last):
  File "/usr/local/lib/python3.8/dist-packages/cheroot/wsgi.py", line 142, in respond
    for chunk in filter(None, response):
  File "/usr/local/lib/python3.8/dist-packages/WsgiDAV-3.0.5a3-py3.8.egg/wsgidav/wsgidav_app.py", line 563, in __call__
    for v in app_iter:
  File "/usr/local/lib/python3.8/dist-packages/WsgiDAV-3.0.5a3-py3.8.egg/wsgidav/debug_filter.py", line 146, in __call__
    _logger.info("{:<20}: '{}'".format(k, safe_re_encode(v, "utf8")))
  File "/usr/local/lib/python3.8/dist-packages/WsgiDAV-3.0.5a3-py3.8.egg/wsgidav/util.py", line 412, in safe_re_encode
    s = s.encode(encoding_to, errors=errors).decode(encoding_to)
AttributeError: 'int' object has no attribute 'encode'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.8/dist-packages/cheroot/server.py", line 1284, in communicate
    req.respond()
  File "/usr/local/lib/python3.8/dist-packages/cheroot/server.py", line 1074, in respond
    self.server.gateway(self).respond()
  File "/usr/local/lib/python3.8/dist-packages/cheroot/wsgi.py", line 148, in respond
    self.req.ensure_headers_sent()
  File "/usr/local/lib/python3.8/dist-packages/cheroot/server.py", line 1121, in ensure_headers_sent
    self.send_headers()
  File "/usr/local/lib/python3.8/dist-packages/cheroot/server.py", line 1139, in send_headers
    status = int(self.status[:3])
ValueError: invalid literal for int() with base 10: ''
sinshutu added a commit to sinshutu/wsgidav that referenced this issue Dec 26, 2020
@sinshutu
Copy link
Contributor

It seemed to be an error because REMOTE_PORT became an int.

Change debug log output

diff --git a/wsgidav/debug_filter.py b/wsgidav/debug_filter.py
index 09e02b7..b91c6de 100644
--- a/wsgidav/debug_filter.py
+++ b/wsgidav/debug_filter.py
@@ -143,6 +143,7 @@ class WsgiDavDebugFilter(BaseMiddleware):
             #         threading.currentThread().ident, method))
             for k, v in environ.items():
                 if k == k.upper():
+                    _logger.info("{:<20}: '{}'".format(k, v))
                     _logger.info("{:<20}: '{}'".format(k, safe_re_encode(v, "utf8")))
             _logger.info("\n")

diff --git a/wsgidav/util.py b/wsgidav/util.py
index 319e256..65afbe7 100644
--- a/wsgidav/util.py
+++ b/wsgidav/util.py
@@ -404,6 +404,7 @@ def safe_re_encode(s, encoding_to, errors="backslashreplace"):
     (e.g. if we don't know the encoding, see #87, #96)
     """
     # prev = s
+    print("safe_re_encode({}, {})".format(s, encoding_to))
     if not encoding_to:
         encoding_to = "ASCII"
     if compat.is_bytes(s):

outout

INFO:werkzeug:172.27.0.1 - - [26/Dec/2020 07:08:16] "OPTIONS /storage/ HTTP/1.1" 500 -              
Traceback (most recent call last):                                                                  
  File "/usr/local/lib/python3.8/site-packages/wsgidav/wsgidav_app.py", line 563, in __call__       
    for v in app_iter:                                                                              
  File "/usr/local/lib/python3.8/site-packages/wsgidav/debug_filter.py", line 147, in __call__      
    _logger.info("{:<20}: '{}'".format(k, safe_re_encode(v, "utf8")))                               
  File "/usr/local/lib/python3.8/site-packages/wsgidav/util.py", line 413, in safe_re_encode        
    s = s.encode(encoding_to, errors=errors).decode(encoding_to)                                    
AttributeError: 'int' object has no attribute 'encode'                                              
INFO:wsgidav.debug_filter:GET Request ---                                                           
INFO:wsgidav.debug_filter:SERVER_SOFTWARE     : 'Werkzeug/1.0.1'                                    
INFO:wsgidav:safe_re_encode(Werkzeug/1.0.1, utf8)                                                   
INFO:wsgidav.debug_filter:SERVER_SOFTWARE     : 'Werkzeug/1.0.1'                                    
INFO:wsgidav.debug_filter:REQUEST_METHOD      : 'GET'                                               
INFO:wsgidav:safe_re_encode(GET, utf8)                                                              
INFO:wsgidav.debug_filter:REQUEST_METHOD      : 'GET'                                               
INFO:wsgidav.debug_filter:SCRIPT_NAME         : '/storage'                                          
INFO:wsgidav:safe_re_encode(/storage, utf8)                                                         
INFO:wsgidav.debug_filter:SCRIPT_NAME         : '/storage'                                          
INFO:wsgidav.debug_filter:PATH_INFO           : '/sample.docx'                                      
INFO:wsgidav:safe_re_encode(/sample.docx, utf8)                                                     
INFO:wsgidav.debug_filter:PATH_INFO           : '/sample.docx'                                      
INFO:wsgidav.debug_filter:QUERY_STRING        : ''                                                  
INFO:wsgidav:safe_re_encode(, utf8)                                                                 
INFO:wsgidav.debug_filter:QUERY_STRING        : ''                                                  
INFO:wsgidav.debug_filter:REQUEST_URI         : '/storage/sample.docx'                              
INFO:wsgidav:safe_re_encode(/storage/sample.docx, utf8)                                             
INFO:wsgidav.debug_filter:REQUEST_URI         : '/storage/sample.docx'                              
INFO:wsgidav.debug_filter:RAW_URI             : '/storage/sample.docx'                              
INFO:wsgidav:safe_re_encode(/storage/sample.docx, utf8)                                             
INFO:wsgidav.debug_filter:RAW_URI             : '/storage/sample.docx'                              
INFO:wsgidav.debug_filter:REMOTE_ADDR         : '172.27.0.1'                                        
INFO:wsgidav:safe_re_encode(172.27.0.1, utf8)                                                       
INFO:wsgidav.debug_filter:REMOTE_ADDR         : '172.27.0.1'                                        
INFO:wsgidav.debug_filter:REMOTE_PORT         : '43866'                                             
INFO:wsgidav:safe_re_encode(43866, utf8)                                                            

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants