【发布时间】:2018-11-19 21:20:54
【问题描述】:
尝试设置电子表格以通过 http 帖子获取数据。为了测试它,我设置了一个简单的 python 脚本来发送一个 http 请求。我不想在 python 或其他地方使用特定的 google api,因为我希望其他人能够简单地发送他们想要的请求。所以,在我的谷歌脚本中,我只有:
function doPost(e){
sheet = SpreadsheetApp.getActiveSheet();
range = sheet.getRange(1, 1)
ange.setValue(e.text)
}
在python中我只有:
import requests
if __name__== "__main__":
params = {'Authorization': "Bearer [token]",
'contentType': 'application/json',
'text': "is working?"}
r = requests.post("https://script.google.com/macros/s/[uniquekey]/exec", params)
print(r.status_code, r.reason)
我得到的只是
“401 未经授权”
我也尝试过通过 python 发送它,以及在网络服务器中和通过 chrome 运行 JS(我猜这会引发安全问题)。一切都给了我同样的回应。我确定我只是没有正确授权,但我还没有找到正确的方法来做到这一点。提前致谢。我敢肯定还有其他一些问题,但我似乎什至无法访问。
【问题讨论】:
标签: python google-apps-script web-applications authorization http-status-code-401