我尝试在 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 是否可以与互联网通信,并且 IDLE 上的光标是否闪烁且没有详细信息?
我已经停用了防火墙commodo,仅此而已。
最佳答案
简短回答:pytumblr
尚不适用于 Python 3。使用Python 2.7。
关于python - 使用 Windows 7 64 位 python 3.5.1 和 pytumblr 在 tumblr 上发布图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34484027/