python - 数据工厂中的 PEM 证书
问题描述
在这方面找不到任何东西。
我正在为 On the market 打一个 API,这是一个英国房地产网站。作为身份验证的一部分,它要求我们提交证书和密钥。这里的文档:
https://media.rightmove.co.uk/ps/pdf/guides/adf/Rightmove_Real_Time_Datafeed_Specification.pdf
(注意:文档指的是 Rightmove,但在市场上使用相同的 API)。
我在数据工厂中看不到任何功能可以做到这一点,有没有人能够克服类似的挑战?
我从 On-the-market 下载了 PEM 证书。我尝试使用 Databricks 脚本进行测试,但尝试加载证书时收到错误消息:
Python脚本:
import http.client
import json
import ssl
# Defining certificate related stuff and host of endpoint
certificate_file = "/mnt/data/certificates/otm/certificate17131114507144750725.pem"
certificate_secret= "<snipped>"
host = 'https://adfapi.rightmove.co.uk/v1'
# Defining parts of the HTTP request
request_url='/property/getbrandemail'
request_headers = {
'Content-Type': 'application/json'
}
# Define the client certificate settings for https connection
context = ssl.SSLContext(ssl.PROTOCOL_SSLv23)
context.load_cert_chain(certfile=certificate_file, password=certificate_secret)
# Create a connection to submit HTTP requests
connection = http.client.HTTPSConnection(host, port=443, context=context)
# Use connection to submit a HTTP POST request
connection.request(method="POST", url=request_url, headers=request_headers, body=json.dumps(request_body_dict))
# Print the HTTP response from the IOT service endpoint
response = connection.getresponse()
print(response.status, response.reason)
data = response.read()
print(data)
错误信息:
FileNotFoundError: [Errno 2] 没有这样的文件或目录 ---------------------------------------- ------------------------------------ FileNotFoundError Traceback (most recent call last) in 20 # 定义客户端https 连接的证书设置 21 context = ssl.SSLContext(ssl.PROTOCOL_SSLv23) ---> 22 context.load_cert_chain(certfile=certificate_file, password=certificate_secret) 23 24 # 创建连接提交HTTP请求
需要明确的是,错误与此行有关:
context.load_cert_chain(certfile=certificate_file, password=certificate_secret)
/mnt/data
是我创建的挂载点,在其他笔记本中运行良好。我的想法是通过笔记本获得响应并通过 ADF 进行编排。感觉应该有一个更简单的解决方案。
解决方案
问题是您使用/mnt/data
的代码不了解 DBFS(默认文件系统)。因此,您需要使用本地文件系统 API - 只需添加/dbfs
到所有路径,例如,/dbfs/mnt/data/...
推荐阅读
- flutter - 加载数据时更改 FutureBuilder 中的状态
- json - 在 Flutter 中对 Json 进行排序
- layout - 盖茨比的每一页都需要 GSAP 时间线
- xcode - mac os - “信任请求错误(-402,653,181)”
- azure - 适用于 Microsoft IIS httpd 10.0 的基于 Azure PCI 合规性 CPE 的漏洞
- python - 如何通过在python中迭代句子中的单词来创建表格?
- firebase - Django rest 不调用自定义身份验证后端?
- python - 如何使用 Yolo 对象检测在推理上平铺图像
- python - 通过WSL在windows中安装像bowtie2这样的生物信息学包
- javascript - div 的样式为 100vh,带有内部滚动,因此当 **滚动期间视口中的每个 **section-wrapper** 时,我需要为每个 **section-wrapper** 切换类**