当前位置: 首页>>代码示例>>Python>>正文


Python urllib_parse.urlencode方法代码示例

本文整理汇总了Python中six.moves.urllib_parse.urlencode方法的典型用法代码示例。如果您正苦于以下问题:Python urllib_parse.urlencode方法的具体用法?Python urllib_parse.urlencode怎么用?Python urllib_parse.urlencode使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在six.moves.urllib_parse的用法示例。


在下文中一共展示了urllib_parse.urlencode方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: avatar_url_from_email

# 需要导入模块: from six.moves import urllib_parse [as 别名]
# 或者: from six.moves.urllib_parse import urlencode [as 别名]
def avatar_url_from_email(email, size=64, default="retro", dns=False):
    """
    Our own implementation since fas doesn't support this nicely yet.
    """
    if not email:
        return
    if dns:  # pragma: no cover
        # This makes an extra DNS SRV query, which can slow down our webapps.
        # It is necessary for libravatar federation, though.
        import libravatar

        return libravatar.libravatar_url(
            openid=email, size=size, default=default
        )
    else:
        query = urlencode({"s": size, "d": default})
        email = email.encode("utf-8")
        hashhex = hashlib.sha256(email).hexdigest()
        return "https://seccdn.libravatar.org/avatar/%s?%s" % (hashhex, query) 
开发者ID:Pagure,项目名称:pagure,代码行数:21,代码来源:query.py

示例2: __direct_dl

# 需要导入模块: from six.moves import urllib_parse [as 别名]
# 或者: from six.moves.urllib_parse import urlencode [as 别名]
def __direct_dl(self, media_id, torrent=False):
        try:
            data = urllib_parse.urlencode({'src': media_id})
            response = self.net.http_POST(direct_dl_path, form_data=data, headers=self.headers).content
            result = json.loads(response)
            if 'status' in result:
                if result.get('status') == 'success':
                    if torrent:
                        _videos = [(int(item.get('size')), item.get('link')) for item in result.get("content")
                                   if any(item.get('path').lower().endswith(x)
                                          for x in FORMATS)]
                        try:
                            return max(_videos)[1]
                        except ValueError:
                            raise ResolverError('Failed to locate largest video file')
                    else:
                        return result.get('location', None)
                else:
                    raise ResolverError('Link Not Found: Error Code: %s' % result.get('status'))
            else:
                raise ResolverError('Unexpected Response Received')
        except:
            pass

        return None 
开发者ID:tvaddonsco,项目名称:script.module.urlresolver,代码行数:27,代码来源:premiumize_me.py

示例3: get_media_url

# 需要导入模块: from six.moves import urllib_parse [as 别名]
# 或者: from six.moves.urllib_parse import urlencode [as 别名]
def get_media_url(self, host, media_id):
        common.logger.log('in get_media_url %s : %s' % (host, media_id))
        if self.token is None:
            raise ResolverError('No MD Token Available')

        url = self.base_url + '?' + urllib_parse.urlencode({'action': 'getLink', 'token': self.token})
        data = {'link': media_id}
        html = self.net.http_POST(url, form_data=data, headers=self.headers).content
        js_data = json.loads(html)
        if js_data.get('response_code') == 'ok':
            if 'debridLink' in js_data:
                stream_url = js_data['debridLink'].strip('"')
                if stream_url.startswith('http'):
                    return stream_url
                else:
                    msg = 'MD Unusable Link: %s' % (stream_url)
            else:
                msg = 'MD No Link'
        else:
            msg = js_data.get('response_text', 'Unknown MD Error during resolve')

        logger.log_warning(msg)
        if isinstance(msg, six.text_type) and six.PY2:
            msg = msg.encode('utf-8')
        raise ResolverError(msg) 
开发者ID:tvaddonsco,项目名称:script.module.urlresolver,代码行数:27,代码来源:megadebrid.py

示例4: login

# 需要导入模块: from six.moves import urllib_parse [as 别名]
# 或者: from six.moves.urllib_parse import urlencode [as 别名]
def login(self):
        try:
            common.logger.log('Mega-debrid - Logging In')
            username = self.get_setting('username')
            password = self.get_setting('password')
            if username and password:
                url = self.base_url + '?' + urllib_parse.urlencode({'action': 'connectUser', 'login': username, 'password': password})
                html = self.net.http_GET(url, headers=self.headers).content
                js_data = json.loads(html)
                if js_data.get('response_code') == 'ok':
                    self.token = js_data['token']
                    return True
                else:
                    msg = js_data.get('response_text', 'Unknown Error')
            else:
                msg = 'No Username/Password'
        except Exception as e:
            msg = str(e)

        raise ResolverError('MD Login Failed: %s' % (msg)) 
开发者ID:tvaddonsco,项目名称:script.module.urlresolver,代码行数:22,代码来源:megadebrid.py

示例5: get_media_url

# 需要导入模块: from six.moves import urllib_parse [as 别名]
# 或者: from six.moves.urllib_parse import urlencode [as 别名]
def get_media_url(self, host, media_id):
        username = self.get_setting('username')
        password = self.get_setting('password')
        url = 'https://premium.rpnet.biz/client_api.php'
        query = urllib_parse.urlencode({'username': username, 'password': password, 'action': 'generate', 'links': media_id})
        url = url + '?' + query
        response = self.net.http_GET(url).content
        response = json.loads(response)
        if 'links' in response and response['links']:
            link = response['links'][0]
            if 'generated' in link:
                return link['generated']
            elif 'error' in link:
                raise ResolverError(link['error'])
        else:
            msg = 'No Link Returned'
            if 'error' in response and response['error']:
                msg += ': %s' % (response['error'][0])
            raise ResolverError(msg) 
开发者ID:tvaddonsco,项目名称:script.module.urlresolver,代码行数:21,代码来源:rpnet.py

示例6: login

# 需要导入模块: from six.moves import urllib_parse [as 别名]
# 或者: from six.moves.urllib_parse import urlencode [as 别名]
def login(self, username, password):
        """Log in to Betfair. Sets `session_token` if successful.

        :param str username: Username
        :param str password: Password
        :raises: BetfairLoginError
        """
        response = self.session.post(
            os.path.join(self.identity_url, 'certlogin'),
            cert=self.cert_file,
            data=urllib.urlencode({
                'username': username,
                'password': password,
            }),
            headers={
                'X-Application': self.app_key,
                'Content-Type': 'application/x-www-form-urlencoded',
            },
            timeout=self.timeout,
        )
        utils.check_status_code(response, [httplib.OK])
        data = response.json()
        if data.get('loginStatus') != 'SUCCESS':
            raise exceptions.LoginError(response, data)
        self.session_token = data['sessionToken'] 
开发者ID:jmcarp,项目名称:betfair.py,代码行数:27,代码来源:betfair.py

示例7: format_yahoo_index_url

# 需要导入模块: from six.moves import urllib_parse [as 别名]
# 或者: from six.moves.urllib_parse import urlencode [as 别名]
def format_yahoo_index_url(symbol, start_date, end_date):
    """
    Format a URL for querying Yahoo Finance for Index data.
    """
    return (
        'http://ichart.finance.yahoo.com/table.csv?' + urlencode({
            's': symbol,
            # start_date month, zero indexed
            'a': start_date.month - 1,
            # start_date day
            'b': start_date.day,
            # start_date year
            'c': start_date.year,
            # end_date month, zero indexed
            'd': end_date.month - 1,
            # end_date day
            'e': end_date.day,
            # end_date year
            'f': end_date.year,
            # daily frequency
            'g': 'd',
        })
    ) 
开发者ID:zhanghan1990,项目名称:zipline-chinese,代码行数:25,代码来源:benchmarks.py

示例8: test_auth_url_provided_forwards_cookies_and_propagates_xsrf

# 需要导入模块: from six.moves import urllib_parse [as 别名]
# 或者: from six.moves.urllib_parse import urlencode [as 别名]
def test_auth_url_provided_forwards_cookies_and_propagates_xsrf(self):
    auth_url = self.get_server_base_url() + '/fake-auth'
    encoded_query_args = urlparse.urlencode(
        {'jupyter_http_over_ws_auth_url': auth_url})

    request = self.get_ws_connection_request('http_over_websocket?' +
                                             encoded_query_args)
    client = yield websocket.websocket_connect(request)
    client.write_message(
        self.get_request_json(
            '/api/sessions', '1234', method='POST', body='somedata'))

    response_body = yield client.read_message()
    response = json.loads(response_body)
    self.assertEqual(200, response['status'])
    self.assertEqual('somedata',
                     base64.b64decode(response['data']).decode('utf-8'))
    self.assertEqual('1234', response['message_id'])
    self.assertIn(TEST_XSRF_HEADER, response['headers'])
    self.assertEqual(FAKE_XSRF_VALUE, response['headers'][TEST_XSRF_HEADER])
    self.assertTrue(response['done']) 
开发者ID:googlecolab,项目名称:jupyter_http_over_ws,代码行数:23,代码来源:handlers_test.py

示例9: test_auth_url_provided_forwards_cookies

# 需要导入模块: from six.moves import urllib_parse [as 别名]
# 或者: from six.moves.urllib_parse import urlencode [as 别名]
def test_auth_url_provided_forwards_cookies(self):
    auth_url = self.get_server_base_url() + '/fake-auth'
    encoded_query_args = urlparse.urlencode(
        {'jupyter_http_over_ws_auth_url': auth_url})

    request = self.get_ws_connection_request('http_over_websocket?' +
                                             encoded_query_args)

    client = yield websocket.websocket_connect(request)
    client.write_message(
        self.get_request_json('/requires-cookies-from-fake-auth', '1234'))

    response_body = yield client.read_message()
    response = json.loads(response_body)
    self.assertEqual(200, response['status'])
    # RequiresCookieFromFakeAuthHandler writes cookies that should have
    # been received by performing a request to the auth url.
    self.assertEqual('X-Test-Cookie: "1" X-Other-Test-Cookie: "2"',
                     base64.b64decode(response['data']).decode('utf-8'))
    self.assertEqual('1234', response['message_id'])
    self.assertTrue(response['done']) 
开发者ID:googlecolab,项目名称:jupyter_http_over_ws,代码行数:23,代码来源:handlers_test.py

示例10: test_auth_url_provided_fails

# 需要导入模块: from six.moves import urllib_parse [as 别名]
# 或者: from six.moves.urllib_parse import urlencode [as 别名]
def test_auth_url_provided_fails(self):
    auth_url = self.get_server_base_url() + '/fake-auth?always_fail=1'
    encoded_query_args = urlparse.urlencode(
        {'jupyter_http_over_ws_auth_url': auth_url})

    request = self.get_ws_connection_request('http_over_websocket?' +
                                             encoded_query_args)

    client = yield websocket.websocket_connect(request)
    client.write_message(
        self.get_request_json('/requires-cookies-from-fake-auth', '1234'))

    response_body = yield client.read_message()
    response = json.loads(response_body)
    self.assertEqual('1234', response['message_id'])
    self.assertEqual(500, response['status'])
    self.assertEqual(
        'Uncaught server-side exception. Check logs for additional details.',
        response['statusText'])
    self.assertTrue(response['done']) 
开发者ID:googlecolab,项目名称:jupyter_http_over_ws,代码行数:22,代码来源:handlers_test.py

示例11: _assertCrossDomainRequestFails

# 需要导入模块: from six.moves import urllib_parse [as 别名]
# 或者: from six.moves.urllib_parse import urlencode [as 别名]
def _assertCrossDomainRequestFails(self, auth_url):
    encoded_query_args = urlparse.urlencode(
        {'jupyter_http_over_ws_auth_url': auth_url})

    request = self.get_ws_connection_request('http_over_websocket?' +
                                             encoded_query_args)

    with testing.ExpectLog(
        'tornado.application',
        'Uncaught error when proxying request',
        required=True) as expect_log:
      client = yield websocket.websocket_connect(request)
      client.write_message(
          self.get_request_json('/requires-cookies-from-fake-auth-ws', '1234'))

      response_body = yield client.read_message()
      response = json.loads(response_body)
      self.assertEqual('1234', response['message_id'])
      self.assertEqual(500, response['status'])
      self.assertEqual(
          'Uncaught server-side exception. Check logs for additional details.',
          response['statusText'])
      self.assertTrue(response['done'])
      self.assertTrue(expect_log.logged_stack) 
开发者ID:googlecolab,项目名称:jupyter_http_over_ws,代码行数:26,代码来源:handlers_test.py

示例12: unauthorized_token_request

# 需要导入模块: from six.moves import urllib_parse [as 别名]
# 或者: from six.moves.urllib_parse import urlencode [as 别名]
def unauthorized_token_request(self):
        """Return request for unauthorized token (first stage)"""

        params = self.request_token_extra_arguments()
        params.update(self.get_scope_argument())
        key, secret = self.get_key_and_secret()
        # decoding='utf-8' produces errors with python-requests on Python3
        # since the final URL will be of type bytes
        decoding = None if six.PY3 else 'utf-8'
        state = self.get_or_create_state()
        auth = OAuth1(
            key,
            secret,
            callback_uri=self.get_redirect_uri(state),
            decoding=decoding,
            signature_method=SIGNATURE_HMAC,
            signature_type=SIGNATURE_TYPE_QUERY
        )
        url = self.REQUEST_TOKEN_URL + '?' + urlencode(params)
        url, _, _ = auth.client.sign(url)
        return url 
开发者ID:BeanWei,项目名称:Dailyfresh-B2C,代码行数:23,代码来源:khanacademy.py

示例13: auth_url

# 需要导入模块: from six.moves import urllib_parse [as 别名]
# 或者: from six.moves.urllib_parse import urlencode [as 别名]
def auth_url(self):
        """Return redirect url"""
        state = None
        if self.STATE_PARAMETER or self.REDIRECT_STATE:
            # Store state in session for further request validation. The state
            # value is passed as state parameter (as specified in OAuth2 spec),
            # but also added to redirect_uri, that way we can still verify the
            # request if the provider doesn't implement the state parameter.
            # Reuse token if any.
            name = self.name + '_state'
            state = self.strategy.session_get(name) or self.state_token()
            self.strategy.session_set(name, state)

        params = self.auth_params(state)
        params.update(self.get_scope_argument())
        params.update(self.auth_extra_arguments())
        return self.AUTHORIZATION_URL + '?' + urlencode(params) 
开发者ID:BeanWei,项目名称:Dailyfresh-B2C,代码行数:19,代码来源:soundcloud.py

示例14: modify_start_url

# 需要导入模块: from six.moves import urllib_parse [as 别名]
# 或者: from six.moves.urllib_parse import urlencode [as 别名]
def modify_start_url(self, start_url):
        """
        Given a SAML redirect URL, parse it and change the ID to
        a consistent value, so the request is always identical.
        """
        # Parse the SAML Request URL to get the XML being sent to TestShib
        url_parts = urlparse(start_url)
        query = dict((k, v[0]) for (k, v) in
                     parse_qs(url_parts.query).items())
        xml = OneLogin_Saml2_Utils.decode_base64_and_inflate(
            query['SAMLRequest']
        )
        # Modify the XML:
        xml = xml.decode()
        xml, changed = re.subn(r'ID="[^"]+"', 'ID="TEST_ID"', xml)
        self.assertEqual(changed, 1)
        # Update the URL to use the modified query string:
        query['SAMLRequest'] = OneLogin_Saml2_Utils.deflate_and_base64_encode(
            xml
        )
        url_parts = list(url_parts)
        url_parts[4] = urlencode(query)
        return urlunparse(url_parts) 
开发者ID:BeanWei,项目名称:Dailyfresh-B2C,代码行数:25,代码来源:test_saml.py

示例15: fetch_report

# 需要导入模块: from six.moves import urllib_parse [as 别名]
# 或者: from six.moves.urllib_parse import urlencode [as 别名]
def fetch_report(report_type, match=None, partition=None):
    """Fetch a report of the given type and return it as a DataFrame."""
    api_urls = context.GLOBAL.cell_api()
    path = '/scheduler/{}'.format(report_type)

    query = {}
    if match:
        query['match'] = match
    if partition:
        query['partition'] = partition

    if query:
        path += '?' + urllib_parse.urlencode(query)

    response = restclient.get(api_urls, path).json()
    return pd.DataFrame(response['data'], columns=response['columns']) 
开发者ID:Morgan-Stanley,项目名称:treadmill,代码行数:18,代码来源:__init__.py


注:本文中的six.moves.urllib_parse.urlencode方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。