跳至主要內容
  • Hostloc 空間訪問刷分
  • 售賣場
  • 廣告位
  • 賣站?

4563博客

全新的繁體中文 WordPress 網站
  • 首頁
  • 云函数无法写入
未分類
13 6 月 2021

云函数无法写入

云函数无法写入

資深大佬 : zhuangzhelia9908 5

import string
import requests
SCKEY = ‘666’
url2 = ‘https://api.tokyo.biliob233.com/user/check-in’
cookie2 = ‘666’
def it():
headers = {
‘user-agent’: ‘Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.163 Safari/537.36’, ‘cookie’: cookie2
}
res = requests.post(url=url2, headers=headers).text
f = open(“bilibiliob.txt”, ‘w+’)
f.write(res)
f.close()
# 微信推送
ssckey = SCKEY
send_url = ‘https://sc.ftqq.com/’ + ssckey + ‘.send’
with open(‘bilibiliob.txt’, ‘a+’) as f2:
text = f2.read()
punctuation_string = string.punctuation
for i in punctuation_string:
text = text.replace(i, ”)
if ‘code1msg 未登录’ or ‘code1msg 已经签过到了’ in text:
params = {
‘text’: ‘bilibiliob 签到失败提醒’
}
else:
params = {
‘text’: ‘bilibiliob 签到提醒’
}
requests.post(send_url, params=params)
def main_handler(event, context):
return it()
if __name__ == ‘__main__’:
it()
程序能行了,可放在云函数上不行,请问怎么让云函数能读写文件,或者让程序不需要创建文件就能执行
大佬有話說 (13)

  • 資深大佬 : l4ever

    我帮你格式化一下 https://paste.ubuntu.com/p/Tg2t3jzXVH/

  • 資深大佬 : ihipop

    一般云函数都有个可写的空间有限的 tmp 目录的,文件不大的话写那里面就行了。

  • 資深大佬 : no1xsyzy

    请学 Python

  • 資深大佬 : graetdk

    腾讯云云函数的可写目录是 /tmp/,你要写的话需要在这个目录里写

  • 資深大佬 : l4ever

    给你改改
    https://paste.ubuntu.com/p/Bz6t3wGh2q/

  • 主 資深大佬 : zhuangzhelia9908

    @l4ever 感谢

  • 主 資深大佬 : zhuangzhelia9908

    @graetdk 我找不到>﹏<

  • 主 資深大佬 : zhuangzhelia9908

    @graetdk 麻烦发个具体链接或者图片链接,谢谢

  • 資深大佬 : cdlnls

    上面说的可写目录是 /tmp/ ,你打开文件的时候就这样:f = open(“/tmp/hello.txt”,”w”),加上具体的路径 /tmp 就可以了。

  • 主 資深大佬 : zhuangzhelia9908

    @cdlnls 行了,太感谢你了

  • 主 資深大佬 : zhuangzhelia9908

    @l4ever 这里只需要 session,怎么自动提取它

  • 資深大佬 : no1xsyzy

    你把一个字符串写入一个文件,再从同一个文件把内容读出来,属于如蜜传如蜜
    按 #1 的格式化,去掉 L13-L15,L21-L22,然后把 L23 降一级缩进,前面加一行 text=res 就行了
    反正处理完了文件也会被删,云函数嘛,用过就丢了,存文件完全没必要。

  • 主 資深大佬 : zhuangzhelia9908

    @no1xsyzy 知道了,感谢

文章導覽

上一篇文章
下一篇文章

AD

其他操作

  • 登入
  • 訂閱網站內容的資訊提供
  • 訂閱留言的資訊提供
  • WordPress.org 台灣繁體中文

51la

4563博客

全新的繁體中文 WordPress 網站
返回頂端
本站採用 WordPress 建置 | 佈景主題採用 GretaThemes 所設計的 Memory
4563博客
  • Hostloc 空間訪問刷分
  • 售賣場
  • 廣告位
  • 賣站?
在這裡新增小工具