python - 将 pandas DataFrame 转换为 MS Graph APi 的字节
问题描述
我使用 MS Graph Api 将数据框作为电子邮件附件发送..下面的文档
https://docs.microsoft.com/en-us/graph/api/user-sendmail?view=graph-rest-1.0&tabs=http。.
附件需要在contentBytes
现场发送
所以使用这个功能:
def convertToBytesString(mmcFile):
mmcFileBytes = pickle.dumps(mmcFile.to_csv(index = False), protocol= 4)
mmcFileBytes = base64.b64encode(mmcFileBytes).decode()
return mmcFileBytes
然后我将返回mmcFileBytes
的数据传递给 MS 图表,例如:
{
"message": {
"subject": "Meet for lunch?",
"body": {
"contentType": "Text",
"content": "The new cafeteria is open."
},
"toRecipients": [
{
"emailAddress": {
"address": "test@gmail.com"
}
}
],
"attachments": [
{
"@odata.type": "#microsoft.graph.fileAttachment",
"name": "attachment.csv",
"contentType": "text/plain",
"contentBytes": mmcFileBytes
}
]
}
}
.csv
电子邮件按预期发送附件,但我在or 单元格的第一行有奇怪的字符A1
。
€X£ÿMetavehicle Id
我只是想要Metavehicle Id
如果我print()
在上面的函数中添加一个...
def convertToBytesString(mmcFile):
mmcFileBytes = pickle.dumps(mmcFile.to_csv(index = False), protocol= 4)
print(mmcFileBytes)
mmcFileBytes = base64.b64encode(mmcFileBytes).decode()
return mmcFileBytes
返回的长字符串的第一部分是b'\x80\x04X\xa3\xff\x01\x00Metavehicle Id
所以我只能假设这\x80\x04X\xa3\xff\x01\x00
是问题所在。
我的功能是否有任何遗漏可能导致这种情况?
解决方案
推荐阅读
- salesforce - 如何将值从一个 VF 页面传递到另一个页面并刷新发送值的页面(两个 vf 页面都将用作闪电记录页面上的组件)
- reactjs - React Native & Firebase Cloud Messaging:如何避免重复推送通知?
- javascript - 防止元素拖出画布
- python - 为什么 htttp.get 在 Flutter 中给我一个错误
- python - 训练验证和测试集(生产数据)中的一种热编码
- javascript - 提示功能不接受仅包含数字的输入
- blackberry - 在 IOS 14 设备中单击输入类型日期时,Blackberry Access App 崩溃
- angular - 在 Angular 应用程序中使用地理编码 API 时出现 COORS 错误
- sql - SQL INSERT from 1 table to another , WHERE 两个表中的现有列共享相同的内容
- javascript - 是否可以从 Angular 10 的主 JS 包中删除组件样式?