首页 > 解决方案 > 数据工厂中的 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 进行编排。感觉应该有一个更简单的解决方案。

标签: pythonazure-data-factory-2azure-databrickspem

解决方案


问题是您使用/mnt/data的代码不了解 DBFS(默认文件系统)。因此,您需要使用本地文件系统 API - 只需添加/dbfs到所有路径,例如,/dbfs/mnt/data/...


推荐阅读