使用Windows 7 64位python 3.5.1和pytumblr在tumblr上发布图像?

时间:2015-12-27 19:30:10

标签: python api tumblr pytumblr

我尝试在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

我使用IDLE的python(F5)启动,没有任何附加光标在shell中闪烁,但在tumblr上没有图像帖子。我检查防火墙没问题。

我卸载Python 2.7.11并安装Python 3.5.1 pytubmlrpylint

我用这个代替第一行:

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上的光标闪烁没有详细信息?

我有防火墙,我停用了,仅此而已。

1 个答案:

答案 0 :(得分:2)

简短回答:pytumblr尚未与Python 3兼容。使用Python 2.7。

相关问题