我正在尝试使用python将图片发布到tumblr,尤其是:http://code.google.com/p/python-tumblr/
#!/usr/bin/python
from tumblr import Api
import sys
BLOG='example.tumblr.com'
USER='example@example.com'
PASSWORD='example'
api = Api(BLOG,USER,PASSWORD)
post_data = "picture.png"
title = "Title of my entry"
body = "this is a story with a picture"
api.write_regular(title, body + post_data)
当我运行此命令时,结果是博客到达,而不是:
Title of my entry
this is a story with a picture
[img]
我得到这个:
Title of my entry
this is a story with a
picturepicture.png
解决方法:
在您当前的代码中,您没有发布图像,而是发送了一个称为“ picture.png”的字符串.正如Daniel DiPaolo所说,您必须使用写照片.例如,write_photo的参数是指向图像的链接.
#!/usr/bin/python
from tumblr import Api
import sys
BLOG='example.tumblr.com'
USER='example@example.com'
PASSWORD='example'
api = Api(BLOG,USER,PASSWORD)
api.write_photo('http://example.org/somewhere/lolcat.jpg')
如果要发送HTML,则可以创建一个长为包含所选标签的正文.
title = "life is amazing"
body = """
_here my html code_
"""
然后用API编写
api.write_regular(title,body)
而且你应该准备好了.
资料上传
更精确地说;)如果要发送数据,则必须打开对象.
假设您的图片是“ lolcat.jpg”
数据= open(‘lolcat.jpg’).read()
标签:python,tumblr 来源: https://codeday.me/bug/20191023/1913652.html
本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享; 2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关; 3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关; 4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除; 5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。