如何使用Python在Azure Synapse中为Salesforce创建关联服务

huangapple go评论70阅读模式
英文:

How to create Linked Service for Salesforce in Azure Synapse using Python

问题

根据要求,我正在使用Python与Azure Synapse环境一起工作。我需要创建一个Salesforce的Linked Service,以便稍后在管道中使用。

但是我遇到了一个错误,而且无法从Microsoft获取更好的文档。

简化的代码 -

from azure.synapse.artifacts import ArtifactsClient
from azure.synapse.artifacts.models import *

sf_ls_name = "testnotebookls"
sf_env_url = "https://login.salesforce.com"
sf_user = "<username>"
sf_pass = '<password>',
sf_security_token = '<security-token>',

properties = SalesforceLinkedService(environment_url=sf_env_url,
                                     password=sf_pass,
                                     username=sf_user,
                                     security_token=sf_security_token)

client.linked_service.begin_create_or_update_linked_service(linked_service_name=sf_ls_name, properties=properties)

请注意,我已经创建了client对象,并且能够获取链接的服务并执行与Synapse相关的操作。

错误

DeserializationError                      Traceback (most recent call last)
File c:\Users\Someuser\OneDrive - Company\Desktop\folder\folder\salesforce\.venv\lib\site-packages\azure\synapse\artifacts\_serialization.py:710, in Serializer.body(self, data, data_type, **kwargs)
    705         deserializer.key_extractors = [
    706             rest_key_case_insensitive_extractor,
    707             attribute_key_case_insensitive_extractor,
    708             last_rest_key_case_insensitive_extractor,
...
   1257         found_key = key
   1258         break
-> 1260 return data.get(found_key)

SerializationError: (', DeserializationError: (", AttributeError: \'tuple\' object has no attribute \'get\'"', 'Unable to deserialize to object: type', AttributeError("\'tuple\' object has no attribute \'get\'\"))', 'Unable to build a model: (", AttributeError: \'tuple\' object has no attribute \'get\'"', 'Unable to deserialize to object: type', AttributeError("\'tuple\' object has no attribute \'get\'\")))', DeserializationError("AttributeError: 'tuple' object has no attribute 'get'", 'Unable to deserialize to object: type', AttributeError("'tuple' object has no attribute 'get'")))
Output is truncated. View as a scrollable element or open in a text editor. Adjust cell output settings...

希望这有所帮助。

英文:

As per the requirements, I am working with Azure Synapse Environment using Python. I need to create a Linked Service for Salesforce to be utilized in pipeline later.
But I'm facing an error and couldn't get better documentations from Microsoft.

Simplified code -

from azure.synapse.artifacts import ArtifactsClient
from azure.synapse.artifacts.models import *


sf_ls_name = &quot;testnotebookls&quot;
sf_env_url = &quot;https://login.salesforce.com&quot;  
sf_user = &quot;&lt;username&gt;&quot;             
sf_pass = &#39;&lt;password&gt;&#39;,
sf_security_token = &#39;&lt;security-token&gt;&#39;, 
    
properties=SalesforceLinkedService(environment_url=sf_env_url,
                                           password=sf_pass,
                                           username=sf_user,
                                           security_token=sf_security_token)

client.linked_service.begin_create_or_update_linked_service(linked_service_name=sf_ls_name, properties=properties)

Please note down that I've created client object and able to get linked services and perform synapse related operations.

Error

DeserializationError                      Traceback (most recent call last)
File c:\Users\Someuser\OneDrive - Company\Desktop\folder\folder\salesforce\.venv\lib\site-packages\azure\synapse\artifacts\_serialization.py:710, in Serializer.body(self, data, data_type, **kwargs)
    705         deserializer.key_extractors = [
    706             rest_key_case_insensitive_extractor,
    707             attribute_key_case_insensitive_extractor,
    708             last_rest_key_case_insensitive_extractor,
...
   1257         found_key = key
   1258         break
-&gt; 1260 return data.get(found_key)

SerializationError: (&#39;, DeserializationError: (&quot;, AttributeError: \&#39;tuple\&#39; object has no attribute \&#39;get\&#39;&quot;, \&#39;Unable to deserialize to object: type\&#39;, AttributeError(&quot;\&#39;tuple\&#39; object has no attribute \&#39;get\&#39;&quot;))&#39;, &#39;Unable to build a model: (&quot;, AttributeError: \&#39;tuple\&#39; object has no attribute \&#39;get\&#39;&quot;, \&#39;Unable to deserialize to object: type\&#39;, AttributeError(&quot;\&#39;tuple\&#39; object has no attribute \&#39;get\&#39;&quot;))&#39;, DeserializationError(&quot;, AttributeError: &#39;tuple&#39; object has no attribute &#39;get&#39;&quot;, &#39;Unable to deserialize to object: type&#39;, AttributeError(&quot;&#39;tuple&#39; object has no attribute &#39;get&#39;&quot;)))
Output is truncated. View as a scrollable element or open in a text editor. Adjust cell output settings...

答案1

得分: 0

Finally, I am able to solve it, it was because the security_token and password should be a type of SecretBase Class (Which can't be used directly, use child class SecureString)

Example

sf_ls_name = "testnotebookls"
sf_env_url = "https://login.salesforce.com"  
sf_user = "username"
sf_pass = SecureString(value='<password>')
sf_security_token = SecureString(value='<security-token>') 
英文:

Finally I am able to solve it, it was because the security_token and password should be a type of SecretBase Class (Which can't be used directly, use child class SecureString)

Example

sf_ls_name = &quot;testnotebookls&quot;
sf_env_url = &quot;https://login.salesforce.com&quot;  
sf_user = &quot;username&quot;
sf_pass = SecureString(value=&#39;&lt;password&gt;&#39;)
sf_security_token = SecureString(value=&#39;&lt;security-token&gt;&#39;) 

huangapple
  • 本文由 发表于 2023年6月6日 15:43:06
  • 转载请务必保留本文链接:https://go.coder-hub.com/76412417.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定