Search code examples
pythonapitumblrpytumblr

Post image on tumblr with windows 7 64bit python 3.5.1 and pytumblr?


I try to post scheduled multi tag image on tumblr in a silent way (no GUI) on windows 7 64bit.

I first try with imacro and firefox. It is working but I can't make multi tag and is not silent.

Then I try with apigee and imacro but data must be Array (URL-encoded binary contents) i don't know to do that and is not silent.

Then I try with python and pytumblr: I install python 2.7.11, then pytumblr 0.0.6 (with pip install pytumblr). I find a script on internet i edit it:

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")

I replace of course my-blog by my domaine name of tumblr blog. I create a file with tumblr_keys.py:

consumer_key = ''
consumer_secret = ''
token_key = ''
token_secret = ''

I create an application on tumblr side and is activate and allow https://api.tumblr.com/console/calls/user/info

I launch with IDLE of python (F5) and nothing append cursor blink in the shell but on tumblr no image post. I check my firewall no problem.

I uninstall Python 2.7.11 and install Python 3.5.1 pytubmlr and pylint:

I replace first line with this:

import sys
if "F:\\Python35-32\\Lib\\site-packages\\pytumblr" not in sys.path:
    sys.path.append("F:\\Python35-32\\Lib\\site-packages\\pytumblr")

So, the path changes to the new install.

This time is better because IDLE is verbose:

    from request import TumblrRequest
  File "F:\Python35-32\Lib\site-packages\pytumblr\request.py", line 37
    except RedirectLimit, e:
                        ^
SyntaxError: invalid syntax

I replace, as found on SO, except RedirectLimit, e: to except RedirectLimit as e:

Same problem in line 61 and line 75. I replace:

ImportError: No module named 'urllib2'

Now, I feel this code must be written for an older release of Python but I continued and replace line 1 to 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

Yet, there is an error again:

  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()

As this point I cannot find a solution. As you can see is the first time I use Python. Can you help me?

Thanks.

Edit on 28/12/2015 :

I try on python 2.7.11 simple code :

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)

For check python can communicate with internet and the cursor on IDLE blink with no verbose ?

I have got firewall commodo i desactivate and nothing more.


Solution

  • Short answer: pytumblr does not work with Python 3 yet. Use Python 2.7.