10-14-2019 04:00 AM
Hello
I try to work with webex cards.
I can send a request on the website https://developer.webex.com/docs/api/v1/messages/create-a-message and it works
See print screen
If I try the same with Python requests it does not work:
import requests from requests_toolbelt.multipart.encoder import MultipartEncoder m = MultipartEncoder ( { "roomId": "Y2lzY29zcGFyazovL3VzL1ddddddddddjEyMi0zZTE5LWI4MTQtOWEdddddddddd", "attachments": { "contentType": "application/vnd.microsoft.card.adaptive", "content": { "type": "AdaptiveCard", "version": "1.0", "body": [ { "type": "TextBlock", "text": "Adaptive Cards", "size": "large" } ], "actions": [ { "type": "Action.OpenUrl", "url": "http://adaptivecards.io", "title": "Learn More" } ] } }, "text": "test" } ) r = requests.post ( 'https://api.ciscospark.com/v1/messages', data=m, headers={ 'Authorization': 'Bearer MyKEY', 'Content-Type': m.content_type} ) print ( r.text )
Error message:
AttributeError: 'dict' object has no attribute 'encode'
Solved! Go to Solution.
10-17-2019 03:04 PM - edited 10-17-2019 03:05 PM
This kind of 'attachment' is different from the usual mime-multipart attachment, i.e. used to upload files...perhaps you were making things a bit harder than needed :)
This seems to work for me:
import requests # from requests_toolbelt.multipart.encoder import MultipartEncoder # m = MultipartEncoder ( { m = { "roomId": "Y2lzY29zcGFyazovL3VzL1JPT00vOGQ4YmEwZTAtMTlkNy0xMWU2LTg1OWEtOWYxODkzNjRkMGUx", "attachments": { "contentType": "application/vnd.microsoft.card.adaptive", "content": { "type": "AdaptiveCard", "version": "1.0", "body": [ { "type": "TextBlock", "text": "Adaptive Cards", "size": "large" } ], "actions": [ { "type": "Action.OpenUrl", "url": "http://adaptivecards.io", "title": "Learn More" } ] } }, "text": "test" } # r = requests.post ( 'https://api.ciscospark.com/v1/messages', data=m, r = requests.post ( 'https://api.ciscospark.com/v1/messages', json=m, headers={ 'Authorization': 'Bearer {redacted}', 'Content-Type': 'application/json' } ) print ( r.text )
10-17-2019 03:04 PM - edited 10-17-2019 03:05 PM
This kind of 'attachment' is different from the usual mime-multipart attachment, i.e. used to upload files...perhaps you were making things a bit harder than needed :)
This seems to work for me:
import requests # from requests_toolbelt.multipart.encoder import MultipartEncoder # m = MultipartEncoder ( { m = { "roomId": "Y2lzY29zcGFyazovL3VzL1JPT00vOGQ4YmEwZTAtMTlkNy0xMWU2LTg1OWEtOWYxODkzNjRkMGUx", "attachments": { "contentType": "application/vnd.microsoft.card.adaptive", "content": { "type": "AdaptiveCard", "version": "1.0", "body": [ { "type": "TextBlock", "text": "Adaptive Cards", "size": "large" } ], "actions": [ { "type": "Action.OpenUrl", "url": "http://adaptivecards.io", "title": "Learn More" } ] } }, "text": "test" } # r = requests.post ( 'https://api.ciscospark.com/v1/messages', data=m, r = requests.post ( 'https://api.ciscospark.com/v1/messages', json=m, headers={ 'Authorization': 'Bearer {redacted}', 'Content-Type': 'application/json' } ) print ( r.text )
10-19-2019 01:11 AM
Discover and save your favorite ideas. Come back to expert answers, step-by-step guides, recent topics, and more.
New here? Get started with these tips. How to use Community New member guide