本文整理汇总了Python中requests.compat方法的典型用法代码示例。如果您正苦于以下问题:Python requests.compat方法的具体用法?Python requests.compat怎么用?Python requests.compat使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类requests
的用法示例。
在下文中一共展示了requests.compat方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: open_remote
# 需要导入模块: import requests [as 别名]
# 或者: from requests import compat [as 别名]
def open_remote(url, entry, container, user_parameters, description, http_args,
page_size=None, auth=None, getenv=None, getshell=None):
"""Create either local direct data source or remote streamed source"""
from intake.container import container_map
import msgpack
import requests
from requests.compat import urljoin
if url.startswith('intake://'):
url = url[len('intake://'):]
payload = dict(action='open',
name=entry,
parameters=user_parameters,
available_plugins=list(plugin_registry.keys()))
req = requests.post(urljoin(url, '/v1/source'),
data=msgpack.packb(payload, **pack_kwargs),
**http_args)
if req.ok:
response = msgpack.unpackb(req.content, **unpack_kwargs)
if 'plugin' in response:
pl = response['plugin']
pl = [pl] if isinstance(pl, str) else pl
# Direct access
for p in pl:
if p in plugin_registry:
source = plugin_registry[p](**response['args'])
proxy = False
break
else:
proxy = True
else:
proxy = True
if proxy:
response.pop('container')
response.update({'name': entry, 'parameters': user_parameters})
if container == 'catalog':
response.update({'auth': auth,
'getenv': getenv,
'getshell': getshell,
'page_size': page_size
# TODO ttl?
# TODO storage_options?
})
source = container_map[container](url, http_args, **response)
source.description = description
return source
else:
raise Exception('Server error: %d, %s' % (req.status_code, req.reason))