问题描述
我尝试运行以下python代码以使用Azure ML Studio中的执行Python脚本"模块更新Saleforce中的记录,但出现写入超时错误.但是,相同的代码可以从我的本地pycharm编辑器成功运行.请帮忙 我确定并解决问题
def azureml_main(dataframe1 = None,dataframe2 = None):
将熊猫作为pd导入
导入请求,json
#SF参数
Consumer_key =" xxx"
Consumer_secret =" xxx"
用户名="xxx"
密码="xxx"
security_token =" xxx"
有效载荷= {
'grant_type':'密码',
'client_id':消费者密钥,
'client_secret':consumer_secret,
'用户名':用户名,
'password':密码+ security_token
}
r = request.post("https://test.salesforce.com/services/oauth2/token",
标头= {内容类型":"application/x-www-form-urlencoded"},
data = payload)
输出= json.loads(r.content)
access_token = output ["access_token"]
instance_url = output ["instance_url"]
打印(访问令牌:",access_token)
打印(实例URL",instance_url)
Opportunity_id =" xxx"
标头= {
'Accept-Encoding':'gzip',
'授权':'承载者%s'%access_token
}
r = request.request('patch',instance_url +'/services/data/v39.0/sobjects/Opportunity/'+ Opportunity_id,headers = headers,data = {'Opportunity_Insights__c':'hdshsgdgfdfdttttt'},timeout = 150)
print('Debug:API%s call:%s'%('patch',r.url))
I tried running the following python code to update a record in Saleforce using 'Execute Python Script' module from Azure ML Studio but I'm getting a write timeout error. However, the same code runs successfully from my local pycharm editor. Please help me identify and fix the issue
def azureml_main(dataframe1=None, dataframe2=None):
import pandas as pd
import requests, json
# SF parameters
consumer_key = "xxx"
consumer_secret = "xxx"
username = "xxx"
password = "xxx"
security_token = "xxx"
payload = {
'grant_type': 'password',
'client_id': consumer_key,
'client_secret': consumer_secret,
'username': username,
'password': password + security_token
}
r = requests.post("https://test.salesforce.com/services/oauth2/token",
headers={"Content-Type": "application/x-www-form-urlencoded"},
data=payload)
output = json.loads(r.content)
access_token = output["access_token"]
instance_url = output["instance_url"]
print("Access Token:", access_token)
print("Instance URL", instance_url)
Opportunity_id = "xxx"
headers = {
'Accept-Encoding': 'gzip',
'Authorization': 'Bearer %s' % access_token
}
r = requests.request('patch', instance_url + '/services/data/v39.0/sobjects/Opportunity/' + Opportunity_id, headers=headers,data={'Opportunity_Insights__c': 'hdshsgdgfdfdttttt'},timeout=150)
print('Debug: API %s call: %s' % ('patch', r.url))
收到以下错误:
推荐答案
很抱歉听到您遇到此问题. Machine Learning studio中的错误0085是自定义脚本的语法错误.由于您可以在PyCharm中成功运行代码,因此建议您检查是否已导入一些关键程序包 IDE.
Sorry to hear you are suffering from this issue. Error 0085 in Machine Learning studio is syntax error of the custom script. Since you can run the code successfully in PyCharm, I would suggest you to check if you have import some critical packages in you IDE.
此致
雨桐
这篇关于通过修补程序请求从Azure ML向Salesforce写入时写入超时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!