Guest User

Untitled

a guest
Aug 6th, 2018
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.13 KB | None | 0 0
  1. SalesforceMalformedRequest: Malformed request
  2. https://my_org.my.salesforce.com/services/data/v38.0/sobjects/Attachment/.
  3. Response content: [{
  4. 'message': "Json Deserialization failed on token 'null' and has left off in the middle of parsing a row. Will go to end of row to begin parsing the next row",
  5. 'errorCode': 'INVALID_FIELD'}]
  6.  
  7. from simple_salesforce import Salesforce
  8. from base64 import b64encode
  9. import json
  10.  
  11. userName = 'my_username@test.com'
  12. password = 'mypw'
  13. securityToken = 'mytoken'
  14. svc = Salesforce(username=userName, password=password, security_token=securityToken)
  15. ENCODING = 'utf-8'
  16. name = 'test.txt'
  17. parent_id = '5001I000006rNenQAE'
  18.  
  19.  
  20. with open(name, 'rb') as open_file:
  21. byte_content = open_file.read()
  22. base64_bytes = b64encode(byte_content)
  23. base64_string = base64_bytes.decode(ENCODING)
  24. json_data = json.dumps({
  25. 'ParentId' : parent_id,
  26. 'Name' : name,
  27. 'Body' : base64_string
  28. })
  29.  
  30. result = svc.Attachment.create(json_data)
  31. print(result)
  32.  
  33. svc.Attachment.create({ 'ParentId': parent_id, 'Name': name, 'Body': base64_string })
Add Comment
Please, Sign In to add comment