云函数无法写入 - V2EX
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
zhuangzhelia9908

云函数无法写入

  •  
  •   zhuangzhelia9908 Jun 24, 2021 2117 views
    This topic created in 1783 days ago, the information mentioned may be changed or developed.
    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 replies    2021-06-25 16:18:29 +08:00
    luckyc
        1
    luckyc  
       Jun 24, 2021   1
    ihipop
        2
    ihipop  
       Jun 24, 2021 via Android
    一般云函数都有个可写的空间有限的 tmp 目录的,文件不大的话写那里面就行了。
    no1xsyzy
        3
    no1xsyzy  
       Jun 24, 2021
    请学 Python
    graetdk
        4
    graetdk  
       Jun 24, 2021
    腾讯云云函数的可写目录是 /tmp/,你要写的话需要在这个目录里写
    luckyc
        5
    luckyc  
       Jun 24, 2021   1
    zhuangzhelia9908
        6
    zhuangzhelia9908  
    OP
       Jun 24, 2021
    @l4ever 感谢
    zhuangzhelia9908
        7
    zhuangzhelia9908  
    OP
       Jun 24, 2021
    @graetdk 我找不到><
    zhuangzhelia9908
        8
    zhuangzhelia9908  
    OP
       Jun 24, 2021
    @graetdk 麻烦发个具体链接或者图片链接,谢谢
    cctv6
        9
    cctv6  
       Jun 24, 2021   1
    上面说的可写目录是 /tmp/ ,你打开文件的时候就这样:f = open("/tmp/hello.txt","w"),加上具体的路径 /tmp 就可以了。
    zhuangzhelia9908
        10
    zhuangzhelia9908  
    OP
       Jun 24, 2021
    @cdlnls 行了,太感谢你了
    zhuangzhelia9908
        11
    zhuangzhelia9908  
    OP
       Jun 24, 2021
    @l4ever 这里只需要 session,怎么自动提取它
    no1xsyzy
        12
    no1xsyzy  
       Jun 25, 2021
    你把一个字符串写入一个文件,再从同一个文件把内容读出来,属于如蜜传如蜜

    按 #1 的格式化,去掉 L13-L15,L21-L22,然后把 L23 降一级缩进,前面加一行 text=res 就行了
    反正处理完了文件也会被删,云函数嘛,用过就丢了,存文件完全没必要。
    zhuangzhelia9908
        13
    zhuangzhelia9908  
    OP
       Jun 25, 2021
    @no1xsyzy 知道了,感谢
    About     Help     Advertise     Blog     API     FAQ     Solana     5639 Online   Highest 6679       Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 51ms UTC 08:34 PVG 16:34 LAX 01:34 JFK 04:34
    Do have faith in what you're doing.
    ubao msn snddm index pchome yahoo rakuten mypaper meadowduck bidyahoo youbao zxmzxm asda bnvcg cvbfg dfscv mmhjk xxddc yybgb zznbn ccubao uaitu acv GXCV ET GDG YH FG BCVB FJFH CBRE CBC GDG ET54 WRWR RWER WREW WRWER RWER SDG EW SF DSFSF fbbs ubao fhd dfg ewr dg df ewwr ewwr et ruyut utut dfg fgd gdfgt etg dfgt dfgd ert4 gd fgg wr 235 wer3 we vsdf sdf gdf ert xcv sdf rwer hfd dfg cvb rwf afb dfh jgh bmn lgh rty gfds cxv xcv xcs vdas fdf fgd cv sdf tert sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf shasha9178 shasha9178 shasha9178 shasha9178 shasha9178 liflif2 liflif2 liflif2 liflif2 liflif2 liblib3 liblib3 liblib3 liblib3 liblib3 zhazha444 zhazha444 zhazha444 zhazha444 zhazha444 dende5 dende denden denden2 denden21 fenfen9 fenf619 fen619 fenfe9 fe619 sdf sdf sdf sdf sdf zhazh90 zhazh0 zhaa50 zha90 zh590 zho zhoz zhozh zhozho zhozho2 lislis lls95 lili95 lils5 liss9 sdf0ty987 sdft876 sdft9876 sdf09876 sd0t9876 sdf0ty98 sdf0976 sdf0ty986 sdf0ty96 sdf0t76 sdf0876 df0ty98 sf0t876 sd0ty76 sdy76 sdf76 sdf0t76 sdf0ty9 sdf0ty98 sdf0ty987 sdf0ty98 sdf6676 sdf876 sd876 sd876 sdf6 sdf6 sdf9876 sdf0t sdf06 sdf0ty9776 sdf0ty9776 sdf0ty76 sdf8876 sdf0t sd6 sdf06 s688876 sd688 sdf86