将httpie打包到Python“ PYZ”(zipapp)中非常简单,例如使用
$ pip install --upgrade zapp
$ zapp httpie.pyz httpie.__main__:main httpie
$ python ./httpie.pyz --version
1.0.3
现在,我尝试将httpie-aws-authv4作为httpie的插件包括在内,以用于AWS身份验证。 httpie无法接收该插件。
$ zapp httpie-aws4.pyz httpie.__main__:main httpie httpie-aws-authv4
$ python ./httpie-aws4.pyz
usage: http [--json] [--form] [--pretty {all,colors,format,none}]
...
[--auth USER[:PASS]] [--auth-type {basic,digest}]
$ python ./httpie-aws4.pyz -A aws4 http://localhost:9200/
...
http: error: argument --auth-type/-A: invalid choice: u'aws4' (choose from 'basic', 'digest')
应该说
[--auth-type {basic,digest,aws4}]
有谁知道该如何做?
最佳答案
作为记录,我通过将扩展注册到身份验证机制的内置列表中来解决插件加载问题。尽管通过不同的机制,这也使插件可用且可操作。对于zipapp来说,这非常好:
zapp httpie-aws4.pyz httpie.__main__:main httpie httpie-aws-authv4
mkdir -p httpie/plugins
unzip -q -c httpie-aws4.pyz httpie/plugins/__init__.py | gsed \
-e '15i from httpie_aws_authv4 import AWSv4AuthPlugin # ADDED' \
-e '19i AWSv4AuthPlugin, # ADDED' \
> httpie/plugins/__init__.py
zip httpie-aws4.pyz httpie/plugins/__init__.py
然后会根据需要显示
aws4
身份验证机制:python ./httpie-aws4.pyz 2>&1 | grep auth-type
[--auth USER[:PASS]] [--auth-type {aws4,basic,digest}]
关于python - 如何将带有httpie-aws-authv4的httpie捆绑到Python zipapp中?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/58806102/