python - 使用 Google Colab 的 SSL 证书

标签 python python-3.x ssl google-colaboratory

使用 Google Colab 并尝试连接到外部 API。

我已经创建了一组 SSL 证书并想部署它们,我已经安装了我的驱动器并引用了正确的文件夹,但它失败了。

import betfairlightweight

from google.colab import drive 
from google.colab import files
#!pip install -U pyopenssl
drive.mount('content')
    # Change this certs path to wherever you're storing your certificates
certs_path = 'content/My Drive/betfair/'

# Change these login details to your own
my_username = XXXXX
my_password = XXXXX
my_app_key = XXXXX
trading = betfairlightweight.APIClient(username=my_username,
                                       password=my_password,
                                       app_key=my_app_key
                                       ,certs=certs_path)

证书存在,但是当我

certs_path ='content/My Drive/betfair'

!ls certs_path

我得到了错误

ls: cannot access 'certs_path': No such file or directory

如何使用 Colab 指向我的 google 驱动器中正确的证书文件夹

最佳答案

betfairlightweight.APIClient() 调用是否失败?尝试使路径成为绝对路径:/content/My Drive/betfair/

您看到的问题与 !ls certs_path 无关。使用时! Colab 中的运算符来运行 shell 命令,你的 python 变量没有被使用。它将“certs_path”视为文本。

尝试:

!ls /content/My Drive/betfair

确保正确安装了东西。

关于python - 使用 Google Colab 的 SSL 证书,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57360814/

相关文章:

java - 实现 X509TrustManager

python - 根据一些给定的引用元素插入颜色矩阵的元素

python - 使用 XLRD 迭代列中的行

python - 查询时间过长时 psycopg2 游标挂起

python - 是否可以使用文件对象属性获取搁置数据库文件名? (Python)

ssl - weblogic ssl 握手失败信任库问题

python - 查找和替换特定列中的破折号

python - 'str' 对象不能被解释为 python 中的整数

ruby-on-rails - AES-256-GCM Python 密码学与 Rails OpenSSL

apache - 在 DV SSL 的 BEAST 攻击预防方面需要帮助