我尝试在 Windows 7 64 位上以静默方式(无 GUI)在 tumblr 上发布预定的多标签图像。
我首先尝试使用 imacro 和 firefox。它正在工作,但我不能制作多标签并且不是沉默的。
然后我尝试使用 apigee 和 imacro,但数据必须是数组(URL 编码的二进制内容),我不知道该怎么做,也不是沉默。
然后我尝试使用 python 和 pytumblr: 我安装了 python 2.7.11,然后是 pytumblr 0.0.6(使用 pip install pytumblr)。我在互联网上找到一个脚本,我对其进行了编辑:
import sys
if "F:\\Python27\\Lib\\site-packages\\pytumblr" not in sys.path:
sys.path.append("F:\\Python27\\Lib\\site-packages\\pytumblr")
import pytumblr
from tumblr_keys import * #this imports the content in our tumblr_keys.py file
# Authenticate via OAuth
client = pytumblr.TumblrRestClient(
consumer_key,
consumer_secret,
token_key,
token_secret
)
client.create_photo('my-blog', state="published", tags=["testing", "ok"], data="D:\\dessin.jpg")
当然,我用我的 tumblr 博客域名替换了 my-blog。我用 tumblr_keys.py 创建了一个文件:
consumer_key = ''
consumer_secret = ''
token_key = ''
token_secret = ''
我在 tumblr 端创建了一个应用程序并激活并允许 https://api.tumblr.com/console/calls/user/info
我使用 python 的 IDLE (F5) 启动,shell 中没有附加光标闪烁,但在 tumblr 上没有图像发布。我检查了我的防火墙没有问题。
我卸载 Python 2.7.11 并安装 Python 3.5.1 pytubmlr 和 pylint:
我用这个替换第一行:
import sys
if "F:\\Python35-32\\Lib\\site-packages\\pytumblr" not in sys.path:
sys.path.append("F:\\Python35-32\\Lib\\site-packages\\pytumblr")
因此,路径更改为新安装。
这次更好,因为 IDLE 很冗长:
from request import TumblrRequest
File "F:\Python35-32\Lib\site-packages\pytumblr\request.py", line 37
except RedirectLimit, e:
^
SyntaxError: invalid syntax
我将 SO 上的 except RedirectLimit, e: 替换为 except RedirectLimit as e:
第61行和第75行同样的问题,我替换为:
ImportError: No module named 'urllib2'
现在,我觉得这段代码必须是为旧版本的 Python 编写的,但我继续并替换了第 1 到 15 行:
import urllib
try:
import urllib.request as urllib2
except ImportError:
import urllib2
import time
import json
try:
from urllib.parse import urlparse
except ImportError:
from urlparse import urlparse
from urllib.parse import parse_qsl
import oauth2 as oauth
from httplib2 import RedirectLimit
然而,又出现错误:
File "F:\Python35-32\Lib\site-packages\pytumblr\helpers.py", line 20, in validate_params
if len(multiple_data) > 1:
TypeError: object of type 'filter' has no len()
至此我找不到解决方案。如您所见,这是我第一次使用 Python。你能帮帮我吗?
谢谢。
2015 年 12 月 28 日编辑:
我尝试使用 python 2.7.11 简单代码:
import urllib2
def internet_on():
try:
response=urllib2.urlopen('http://173.194.42.5',timeout=1)
return True
print (ok)
except urllib2.URLError as err: pass
return False
print (bad)
为了检查 python 是否可以与 internet 通信并且 IDLE 上的光标闪烁没有冗长?
我有防火墙命令我停用了,仅此而已。
请您参考如下方法:
简短回答:pytumblr 还不能与 Python 3 一起使用。使用 Python 2.7。
