urllib.parse.urlparse不读取参数

时间:2019-05-31 22:25:42

标签: python urllib

我正在尝试在python中读取参数

 urlparse('jdbc:mysql:@localhost:3306/mysql;user:pass?jdbc_driver_name=com.mysql.jdbc.Driver')

根据documentation,参数放在分号后,但示例网址中的参数却是空字符串。

1 个答案:

答案 0 :(得分:2)

从源代码开始:

uses_params = ['', 'ftp', 'hdl', 'prospero', 'http', 'imap',
               'https', 'shttp', 'rtsp', 'rtspu', 'sip', 'sips',
               'mms', 'sftp', 'tel']

仅在此列表中的方案时解析参数。

def urlparse(url, scheme='', allow_fragments=True):
    url, scheme, _coerce_result = _coerce_args(url, scheme)
    splitresult = urlsplit(url, scheme, allow_fragments)
    scheme, netloc, url, query, fragment = splitresult
    if scheme in uses_params and ';' in url: # <------------------------------ Right here
        url, params = _splitparams(url)
    else:
        params = ''
    result = ParseResult(scheme, netloc, url, params, query, fragment)
    return _coerce_result(result)