Git Product home page Git Product logo

pytumblr's Introduction

PyTumblr

Build Status

Installation

Install via pip:

$ pip install pytumblr

Install from source:

$ git clone https://github.com/tumblr/pytumblr.git
$ cd pytumblr
$ python -m build

Usage

Create a client

A pytumblr.TumblrRestClient is the object you'll make all of your calls to the Tumblr API through. Creating one is this easy:

client = pytumblr.TumblrRestClient(
    '<consumer_key>',
    '<consumer_secret>',
    '<oauth_token>',
    '<oauth_secret>',
)

client.info() # Grabs the current user information

Two easy ways to get your credentials to are:

  1. The built-in interactive_console.py tool (if you already have a consumer key & secret)
  2. The Tumblr API console at https://api.tumblr.com/console
  3. Get sample login code at https://api.tumblr.com/console/calls/user/info

Supported Methods

User Methods

client.info() # get information about the authenticating user
client.dashboard() # get the dashboard for the authenticating user
client.likes() # get the likes for the authenticating user
client.following() # get the blogs followed by the authenticating user

client.follow('codingjester.tumblr.com') # follow a blog
client.unfollow('codingjester.tumblr.com') # unfollow a blog

client.like(id, reblogkey) # like a post
client.unlike(id, reblogkey) # unlike a post

Blog Methods

client.blog_info(blogName) # get information about a blog
client.posts(blogName, **params) # get posts for a blog
client.avatar(blogName) # get the avatar for a blog
client.blog_likes(blogName) # get the likes on a blog
client.followers(blogName) # get the followers of a blog
client.blog_following(blogName) # get the publicly exposed blogs that [blogName] follows
client.queue(blogName) # get the queue for a given blog
client.submission(blogName) # get the submissions for a given blog

Post Methods

Creating posts

PyTumblr lets you create all of the various types that Tumblr supports. When using these types there are a few defaults that are able to be used with any post type.

The default supported types are described below.

  • state - a string, the state of the post. Supported types are published, draft, queue, private
  • tags - a list, a list of strings that you want tagged on the post. eg: ["testing", "magic", "1"]
  • tweet - a string, the string of the customized tweet you want. eg: "Man I love my mega awesome post!"
  • date - a string, the customized GMT that you want
  • format - a string, the format that your post is in. Support types are html or markdown
  • slug - a string, the slug for the url of the post you want

We'll show examples throughout of these default examples while showcasing all the specific post types.

Creating a photo post

Creating a photo post supports a bunch of different options plus the described default options * caption - a string, the user supplied caption * link - a string, the "click-through" url for the photo * source - a string, the url for the photo you want to use (use this or the data parameter) * data - a list or string, a list of filepaths or a single file path for multipart file upload

#Creates a photo post using a source URL
client.create_photo(blogName, state="published", tags=["testing", "ok"],
                    source="https://68.media.tumblr.com/b965fbb2e501610a29d80ffb6fb3e1ad/tumblr_n55vdeTse11rn1906o1_500.jpg")

#Creates a photo post using a local filepath
client.create_photo(blogName, state="queue", tags=["testing", "ok"],
                    tweet="Woah this is an incredible sweet post [URL]",
                    data="/Users/johnb/path/to/my/image.jpg")

#Creates a photoset post using several local filepaths
client.create_photo(blogName, state="draft", tags=["jb is cool"], format="markdown",
                    data=["/Users/johnb/path/to/my/image.jpg", "/Users/johnb/Pictures/kittens.jpg"],
                    caption="## Mega sweet kittens")
Creating a text post

Creating a text post supports the same options as default and just a two other parameters * title - a string, the optional title for the post. Supports markdown or html * body - a string, the body of the of the post. Supports markdown or html

#Creating a text post
client.create_text(blogName, state="published", slug="testing-text-posts", title="Testing", body="testing1 2 3 4")
Creating a quote post

Creating a quote post supports the same options as default and two other parameter * quote - a string, the full text of the qote. Supports markdown or html * source - a string, the cited source. HTML supported

#Creating a quote post
client.create_quote(blogName, state="queue", quote="I am the Walrus", source="Ringo")
Creating a link post
  • title - a string, the title of post that you want. Supports HTML entities.
  • url - a string, the url that you want to create a link post for.
  • description - a string, the desciption of the link that you have
#Create a link post
client.create_link(blogName, title="I like to search things, you should too.", url="https://duckduckgo.com",
                   description="Search is pretty cool when a duck does it.")
Creating a chat post

Creating a chat post supports the same options as default and two other parameters * title - a string, the title of the chat post * conversation - a string, the text of the conversation/chat, with diablog labels (no html)

#Create a chat post
chat = """John: Testing can be fun!
Renee: Testing is tedious and so are you.
John: Aw.
"""
client.create_chat(blogName, title="Renee just doesn't understand.", conversation=chat, tags=["renee", "testing"])
Creating an audio post

Creating an audio post allows for all default options and a has 3 other parameters. The only thing to keep in mind while dealing with audio posts is to make sure that you use the external_url parameter or data. You cannot use both at the same time. * caption - a string, the caption for your post * external_url - a string, the url of the site that hosts the audio file * data - a string, the filepath of the audio file you want to upload to Tumblr

#Creating an audio file
client.create_audio(blogName, caption="Rock out.", data="/Users/johnb/Music/my/new/sweet/album.mp3")

#lets use soundcloud!
client.create_audio(blogName, caption="Mega rock out.", external_url="https://soundcloud.com/skrillex/sets/recess")
Creating a video post

Creating a video post allows for all default options and has three other options. Like the other post types, it has some restrictions. You cannot use the embed and data parameters at the same time. * caption - a string, the caption for your post * embed - a string, the HTML embed code for the video * data - a string, the path of the file you want to upload

#Creating an upload from YouTube
client.create_video(blogName, caption="Jon Snow. Mega ridiculous sword.",
                    embed="http://www.youtube.com/watch?v=40pUYLacrj4")

#Creating a video post from local file
client.create_video(blogName, caption="testing", data="/Users/johnb/testing/ok/blah.mov")

Editing a post

Updating a post requires you knowing what type a post you're updating. You'll be able to supply to the post any of the options given above for updates.

client.edit_post(blogName, id=post_id, type="text", title="Updated")
client.edit_post(blogName, id=post_id, type="photo", data="/Users/johnb/mega/awesome.jpg")

Reblogging a Post

Reblogging a post just requires knowing the post id and the reblog key, which is supplied in the JSON of any post object.

client.reblog(blogName, id=125356, reblog_key="reblog_key")

Deleting a post

Deleting just requires that you own the post and have the post id

client.delete_post(blogName, 123456) # Deletes your post :(

A note on tags: When passing tags, as params, please pass them as a list (not a comma-separated string):

client.create_text(blogName, tags=['hello', 'world'], ...)

Getting notes for a post

In order to get the notes for a post, you need to have the post id and the blog that it is on.

data = client.notes(blogName, id='123456')

The results include a timestamp you can use to make future calls.

data = client.notes(blogName, id='123456', before_timestamp=data["_links"]["next"]["query_params"]["before_timestamp"])

Tagged Methods

# get posts with a given tag
client.tagged(tag, **params)

Using the interactive console

This client comes with a nice interactive console to run you through the OAuth process, grab your tokens (and store them for future use).

You'll need pyyaml installed to run it, but then it's just:

$ python interactive_console.py

and away you go! Tokens are stored in ~/.tumblr and are also shared by other Tumblr API clients like the Ruby client.

Running tests

The tests (and coverage reports) are run with nose, like this:

python setup.py test

Copyright and license

Copyright 2013 Tumblr, Inc.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this work except in compliance with the License. You may obtain a copy of the License in the LICENSE file, or at:

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations.

pytumblr's People

Contributors

andyinsf avatar bnroths avatar ceyko avatar codingjester avatar csu avatar cyle avatar dianakhuang avatar dj-ratty avatar dkarivalis avatar granda avatar hugovk avatar jasonpenny avatar jhoonb avatar komapa avatar lkrzysiak avatar martey avatar masj avatar matt-deacalion avatar matthewmayer avatar mbolivar avatar mouhtasi avatar nigel2x4 avatar nostalgebraist avatar omergulen avatar rrennick avatar sanmai avatar seejohnrun avatar sndsgd avatar taylanpince avatar tomislater avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pytumblr's Issues

What is the rate limit of the Tumblr API?

This doesn't happen often, but once in a while, one of my tumblr calls fails.

I was wondering if there is a rate limit (I'll add a sleep() call , in case there is) or if these are just random failures.

Can't use type parameter in posts() function

The field type is listed as an optional argument for posts() function but the validate_params() function disallows type and raises an exception upon its inclusion, making it impossible to call with the type parameter.

i.e., this code:

args = {'type': 'text', 'limit':2}
posts = client.posts(urls[0], **args)

returns this error:

C:\Users-Removed-\AppData\Local\Enthought\Canopy\User\lib\site-packages\pytumblr-0.0.5-py2.7.egg\pytumblr\helpers.pyc in validate_params(valid_options, params)
25 if disallowed_fields:
26 field_strings = ",".join(disallowed_fields)
---> 27 raise Exception("%s are not allowed fields" % field_strings)
28
29 def validate_blogname(fn):

Exception: type are not allowed fields

Support for "answer" posts

Currently there is no support for answer posts. While answer posts cannot be created, they can be edited.

I tried adding the functionality myself, but ran into issues with pytumblr recognizing answer posts. Any ideas?

README.md edit

Editing a post

Updating a post requires you knowing what type a post you're updating and the id of the post. You'll be able to supply to the post any of the options given above for updates.

client.edit_post(blogName, type="photo", id="12312" title="OK", data="/Users/johnb/mega/awesome.jpg"); # edit a post

UnicodeDecodeError when creating photos with unicode filenames

The TumblrRestClient.create_photo method raises a UnicodeDecodeError when the filename is a unicode instance. Coercing it to str fixes the problem. Here's an example traceback:

>>> import pytumblr
>>> t = pytumblr.TumblrRestClient(consumer_key, consumer_secret, oauth_token, oauth_token_secret)
>>> filename = u"/path/to/file"
>>> t.create_photo(blog_name, data=filename)
Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/Users/justin/.virtualenvs/machino/lib/python2.7/site-packages/pytumblr/helpers.py", line 44, in add_dot_tumblr
    return fn(*args, **kwargs)
  File "/Users/justin/.virtualenvs/machino/lib/python2.7/site-packages/pytumblr/__init__.py", line 281, in create_photo
    return self._send_post(blogname, kwargs)
  File "/Users/justin/.virtualenvs/machino/lib/python2.7/site-packages/pytumblr/__init__.py", line 505, in _send_post
    return self.send_api_request("post", url, params, valid_options)
  File "/Users/justin/.virtualenvs/machino/lib/python2.7/site-packages/pytumblr/__init__.py", line 538, in send_api_request
    return self.request.post(url, params, files)
  File "/Users/justin/.virtualenvs/machino/lib/python2.7/site-packages/pytumblr/request.py", line 56, in post
    return self.post_multipart(url, params, files)
  File "/Users/justin/.virtualenvs/machino/lib/python2.7/site-packages/pytumblr/request.py", line 101, in post_multipart
    content_type, body = self.encode_multipart_formdata(params, files)
  File "/Users/justin/.virtualenvs/machino/lib/python2.7/site-packages/pytumblr/request.py", line 137, in encode_multipart_formdata
    body = CRLF.join(L)
UnicodeDecodeError: 'ascii' codec can't decode byte 0xff in position 0: ordinal not in range(128)
>>> t.create_photo(blog_name, data=str(filename))
{u'id': ...}

Support Python3

We should try to support python3, it's 2.X eventually will be deprecated and we should do our best to make sure that we can support it going forward.

500 Internal Server Error at /login when running locally

Hi, I'm trying to run this locally so I can import as photo post types.

I managed to start the server and load the landing page but clicking 'Connect to Tumblr' gives me an internal server error. Please help :$


p.s. I'm not familiar with Python and I couldn't get the server to start using a config file, getting the following error:

$ WP2TUMBLR_SETTINGS=settings.py; python wp2tumblr.py
Traceback (most recent call last):
  File "wp2tumblr.py", line 24, in <module>
    app.config.from_envvar('WP2TUMBLR_SETTINGS')
  File "/Library/Python/2.7/site-packages/flask/config.py", line 107, in from_envvar
    variable_name)
RuntimeError: The environment variable 'WP2TUMBLR_SETTINGS' is not set and as such configuration could not be loaded.  Set this variable and make it point to a configuration file

Your instructions list settings.py but the sample is saved as settings.cfg, I tried saving both (in same folder as wp2tumblr.py and in /settings/settings.py) but nothing worked.

So I tried hardcoding the settings into the wp2tumblr.py file, which got it to run but maybe that's causing a 500 error?

app.config['TUMBLR_CONSUMER_KEY'] = '####'  
app.config['TUMBLR_CONSUMER_SECRET'] = '####'  
app.debug = False  
app.config['DEBUG'] = False  
app.config['SECRET_KEY'] = 'development'  
app.config['LOG_FILE'] = '/log/log_file.log'  

Create interactive console for pytumblr

Create an interactive console people can use to launch directly into the client with keys filled out.

If keys don't exist, walk them through the 3-legged OAuth state and write a JSON file to their home directory.

Error when Creating photo post

Anytime I try uploading an image I keep getting {"meta":{"status":401,"msg":"Not
Authorized"},"response":[]}. with unicode string as the blog name

How to add meta tags to header?

Hi,

This is quite an impressive library and very helpful.

How do I add meta tags to the blog header though?

For twitter cards, I need to add this per blog.

<meta name="twitter:card" content="summary" />
<meta name="twitter:site" content="@flickr" />
<meta name="twitter:title" content="Small Island Developing States Photo Submission" />
<meta name="twitter:description" content="View the album on Flickr." />
<meta name="twitter:image" content="https://farm6.staticflickr.com/5510/14338202952_93595258ff_z.jpg" />

Many Thanks

Oauth2 package dependency?

Hey guys and gals,

I'm starting to transition myself over to Python 3 and decided to play around with pytumblr as a part of that.

Unfortunately, it appears that oauth2 doesn't play nice with Python 3. github issue

Any plans on transitioning the package to using oauthlib? From what I'm reading it appears to be the new go to package in Python for interacting with OAuth.

Even though EOL for Python 2 is a ways off, using oauthlib looks like it would allow someone who actually needs to use Python 3 and would like to use the pytumblr package, the ability to do so easily.

Thanks!

Type argument not working in Posts() function

This seems similar to issue 23. But I'm running python 2.7

I am not able to use the type argument to return posts of a certain type:

client.posts('bassrx',type='video', limit=1)

Output:
Traceback (most recent call last):
File "G:\programming\python\tumblrapi.py", line 13, in
photo_posts = client.posts('bassrx',type='video', limit=1)
File "C:\Python27\lib\site-packages\pytumblr-0.0.5-py2.7.egg\pytumblr\helpers.
py", line 44, in add_dot_tumblr
File "C:\Python27\lib\site-packages\pytumblr-0.0.5-py2.7.egg\pytumblr__init__
.py", line 124, in posts
File "C:\Python27\lib\site-packages\pytumblr-0.0.5-py2.7.egg\pytumblr__init__
.py", line 490, in send_api_request
File "C:\Python27\lib\site-packages\pytumblr-0.0.5-py2.7.egg\pytumblr\helpers.
py", line 27, in validate_params
Exception: type are not allowed fields

I also tried:
client.posts('bassrx','video', limit=1)

Output:
Traceback (most recent call last):
File "G:\programming\python\tumblrapi.py", line 13, in
photo_posts = client.posts('bassrx','video', limit=1)
File "C:\Python27\lib\site-packages\pytumblr-0.0.5-py2.7.egg\pytumblr\helpers.
py", line 44, in add_dot_tumblr
TypeError: posts() takes exactly 2 arguments (4 given)

If I'm doing this wrong, can it be explained how to return posts using the type argument? As it doesn't seem to be spelled out anywhere.

Date not observed for video posts

Hi,

for video posts the date parameter does not seem to be observed for video uploads.

with my_date = '16.12.2014'

post_id = client.create_photo("xxx", state="published", date=my_date,
                                                 caption=caption, tags=tags, data=tumblr_photos)

creates the right post

post_id = client.create_video("xxx", state="published", date=my_date,
                                                     caption=caption, tags=tags, data=tumblr_video)

does not...

Daniel

Updating version in pypy

Hey guys,

I ran into an issue this morning with attempting to reblog posts and adding comments and tags to them. Turned out this was due to an outdated version of pytumblr in pypy that pip is installing (pytumblr 0.0.5). Removing it and reinstalling directly from the git repo (pip install git+https://github.com/tumblr/pytumblr.git) corrected it, but I'm sure others may be running into this issue as well.

I was getting especially confused because looking at the code on the Github repo made it look like it should be working but wasn't.

If updating the version in pypy isn't possible at this time maybe a note could be added to the README to let people know to install directly from git?

Thanks!

How to format custom Tweet?

I see that I can define a Tweet text when posting. I can get it to post the text I create, but it no longer has the link to the post.

How do you get/append that to the Tweet text?

[ fantastically helpful module, BTW! ]

oauth issue

Hello,

I received this error when i launched

python interactive_console.py

I did give correct "consumer key" and "consumer secret" when prompted

I am using latest python and installed required modules it requested using
python setup.py install
Python 2.7.6

Appreciate your help...

Traceback (most recent call last):
File "interactive_console.py", line 65, in
tokens = new_oauth(yaml_path)
File "interactive_console.py", line 32, in new_oauth
print '\nPlease go here and authorize:\n%s?oauth_token=%s' % (authorize_url, request_token['oauth_token'][0])
KeyError: 'oauth_token'

Reblogging with a photo

I've attempted to use pytumblr to reblog a post with an image however I cannot seem to do this properly.

Noticing the reblog method doesn't accept kwargs caption, link, source, and data I added those to the accepted options in init.py. Then naturally I called reblog like: client.reblog(your_blog_name,id=i,reblog_key=key,type='photo',source=ima)

however this results in empty reblogs that do not have the photo uploaded.
additionally, I have tried manually calling client.request.post() as such:
url = "/v2/blog/" + your_blog_name + ".tumblr.com/post/reblog"
kwargs = {"type":"photo", "source":ima, "id":i, "reblog_key":key}
print client.request.post(url, kwargs)

with the same result.

How would I reblog with a photo added?

Clarification on edit_post()

Clarification more than anything, but what's the syntax for using edit_post();

From what I can see:

client.edit_post("nameofblog", 39228373, detail)

I tried looking at the tests, but there isn't one set up.

Any guidance would be appreciated.

Posting image or video using "data" returns 401

I have been using this lib for quite sometime, recently I updated and I am not able to post videos and images using data='local filename' param.

I checked the commit history but did not find anything particular.

I get 401 not authorized for both image and video data post.

client.create_photo

I've just discovered by trial and error that when using client.create_photo method the data parameter (path to photo) must be str (not unicode). However the caption can be unicode. You should specify when you say "string" what type of string too (str or unicode). Thank you.

Improve documentation to be clearer

Right now, our documentation is kind of lacking. We should go a bit more in depth on all the different types of ways to issue a request. Discussion was started in #15.

ImportError

When attempting import in python 3.4 I get the following:
import pytumblr
File "D:\Python34\lib\site-packages\pytumblr__init__.py", line 1, in
from helpers import validate_params, validate_blogname
ImportError: No module named 'helpers'

SSL Error

Hi! After install it, I have the following SSL error by calling info() method:

Traceback (most recent call last):
  File "./tarteso.py", line 48, in <module>
    main()
  File "./tarteso.py", line 35, in main
    descargaFavs()
  File "./tarteso.py", line 28, in descargaFavs
    myInfo = client.info()
  File "build/bdist.linux-armv7l/egg/pytumblr/__init__.py", line 36, in info
  File "build/bdist.linux-armv7l/egg/pytumblr/__init__.py", line 540, in send_api_request
  File "build/bdist.linux-armv7l/egg/pytumblr/request.py", line 41, in get
  File "build/bdist.linux-armv7l/egg/oauth2/__init__.py", line 682, in request
  File "/usr/local/lib/python2.7/dist-packages/httplib2-0.9-py2.7.egg/httplib2/__init__.py", line 1593, in request
    (response, content) = self._request(conn, authority, uri, request_uri, method, body, headers, redirections, cachekey)
  File "/usr/local/lib/python2.7/dist-packages/httplib2-0.9-py2.7.egg/httplib2/__init__.py", line 1335, in _request
    (response, content) = self._conn_request(conn, request_uri, method, body, headers)
  File "/usr/local/lib/python2.7/dist-packages/httplib2-0.9-py2.7.egg/httplib2/__init__.py", line 1257, in _conn_request
    conn.connect()
  File "/usr/local/lib/python2.7/dist-packages/httplib2-0.9-py2.7.egg/httplib2/__init__.py", line 1021, in connect
    self.disable_ssl_certificate_validation, self.ca_certs)
  File "/usr/local/lib/python2.7/dist-packages/httplib2-0.9-py2.7.egg/httplib2/__init__.py", line 80, in _ssl_wrap_socket
    cert_reqs=cert_reqs, ca_certs=ca_certs)
  File "/usr/lib/python2.7/ssl.py", line 487, in wrap_socket
    ciphers=ciphers)
  File "/usr/lib/python2.7/ssl.py", line 241, in __init__
    ciphers)
ssl.SSLError: [Errno 185090050] _ssl.c:344: error:0B084002:x509 certificate routines:X509_load_cert_crl_file:system lib

If I do print certifi.where() I have the following path:

/usr/local/lib/python2.7/dist-packages/certifi-14.05.14-py2.7.egg/certifi/cacert.pem

This run over OSX but crash over Ubuntu on an ARM processor.

How can I solve it?

401 unauthorized errors despite correct credentials

( Note: could be having the same problem as #34 )

I've copied all the credentials directly from the API explore console (where all calls complete successfully), and provided them to the Pytumblr client. However, I still receive 401 errors for any requests to the API. I have confirmed my configuration with someone at Tumblr, as well.

Authentication failure

As I don't have a consumer key or consumer secret as I can't seem to find either on the tumblr site I've set up my authentication like so.

client = pytumblr.TumblrRestClient(
'oauth key',
'oauth secret'
)

This doesn't seem to work, so the question is where do I get the other keys? or are they not necessary as I suspected?

TypeError write() argument 1 must be string or read-only buffer, not bytearray

The code is client.create_audio(tumblr_username, state="published", data=file_path) produces the errors below but when I do client.create_text(tumblr_username, state="published", body=file_path), a post is created on tumblr with the text of the file path, which is the correct file path for the audio.

Why might this be happening?

Traceback (most recent call last):
File "/usr/lib/python2.6/site-packages/gunicorn/workers/sync.py", line 131, in handle_request
respiter = self.wsgi(environ, resp.start_response)
File "/usr/lib/python2.6/site-packages/flask/app.py", line 1836, in call
return self.wsgi_app(environ, start_response)
File "/usr/lib/python2.6/site-packages/flask/app.py", line 1820, in wsgi_app
response = self.make_response(self.handle_exception(e))
File "/usr/lib/python2.6/site-packages/flask/app.py", line 1403, in handle_exception
reraise(exc_type, exc_value, tb)
File "/usr/lib/python2.6/site-packages/flask/app.py", line 1817, in wsgi_app
response = self.full_dispatch_request()
File "/usr/lib/python2.6/site-packages/flask/app.py", line 1477, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/usr/lib/python2.6/site-packages/flask/app.py", line 1381, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "/usr/lib/python2.6/site-packages/flask/app.py", line 1475, in full_dispatch_request
rv = self.dispatch_request()
File "/usr/lib/python2.6/site-packages/flask/app.py", line 1461, in dispatch_request
return self.view_functionsrule.endpoint
File "/var/www/vmail/handle_calls.py", line 389, in send_message
t_client.create_audio(tumblr_username, state="published", data=str_file)
File "build/bdist.linux-x86_64/egg/pytumblr/helpers.py", line 47, in add_dot_tumblr
return fn(_args, *_kwargs)
File "build/bdist.linux-x86_64/egg/pytumblr/init.py", line 387, in create_audio
return self._send_post(blogname, kwargs)
File "build/bdist.linux-x86_64/egg/pytumblr/init.py", line 509, in _send_post
return self.send_api_request("post", url, params, valid_options)
File "build/bdist.linux-x86_64/egg/pytumblr/init.py", line 542, in send_api_request
return self.request.post(url, params, files)
File "build/bdist.linux-x86_64/egg/pytumblr/request.py", line 61, in post
return self.post_multipart(url, params, files)
File "build/bdist.linux-x86_64/egg/pytumblr/request.py", line 111, in post_multipart
content = urllib2.urlopen(r).read()
File "/usr/lib64/python2.6/urllib2.py", line 126, in urlopen
return _opener.open(url, data, timeout)
File "/usr/lib64/python2.6/urllib2.py", line 391, in open
response = self._open(req, data)
File "/usr/lib64/python2.6/urllib2.py", line 409, in _open
'_open', req)
File "/usr/lib64/python2.6/urllib2.py", line 369, in _call_chain
result = func(*args)
File "/usr/lib64/python2.6/urllib2.py", line 1198, in https_open
return self.do_open(httplib.HTTPSConnection, req)
File "/usr/lib64/python2.6/urllib2.py", line 1162, in do_open
h.request(req.get_method(), req.get_selector(), req.data, headers)
File "/usr/lib64/python2.6/httplib.py", line 914, in request
self._send_request(method, url, body, headers)
File "/usr/lib64/python2.6/httplib.py", line 954, in _send_request
self.send(body)
File "/usr/lib64/python2.6/httplib.py", line 759, in send
self.sock.sendall(str)
File "/usr/lib64/python2.6/ssl.py", line 203, in sendall
v = self.send(data[count:])
File "/usr/lib64/python2.6/ssl.py", line 174, in send
v = self._sslobj.write(data)
TypeError: write() argument 1 must be string or read-only buffer, not bytearray
ERROR:gunicorn.error:Error handling request
Traceback (most recent call last):
File "/usr/lib/python2.6/site-packages/gunicorn/workers/sync.py", line 131, in handle_request
respiter = self.wsgi(environ, resp.start_response)
File "/usr/lib/python2.6/site-packages/flask/app.py", line 1836, in call
return self.wsgi_app(environ, start_response)
File "/usr/lib/python2.6/site-packages/flask/app.py", line 1820, in wsgi_app
response = self.make_response(self.handle_exception(e))
File "/usr/lib/python2.6/site-packages/flask/app.py", line 1403, in handle_exception
reraise(exc_type, exc_value, tb)
File "/usr/lib/python2.6/site-packages/flask/app.py", line 1817, in wsgi_app
response = self.full_dispatch_request()
File "/usr/lib/python2.6/site-packages/flask/app.py", line 1477, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/usr/lib/python2.6/site-packages/flask/app.py", line 1381, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "/usr/lib/python2.6/site-packages/flask/app.py", line 1475, in full_dispatch_request
rv = self.dispatch_request()
File "/usr/lib/python2.6/site-packages/flask/app.py", line 1461, in dispatch_request
return self.view_functionsrule.endpoint
File "/var/www/vmail/handle_calls.py", line 389, in send_message
t_client.create_audio(tumblr_username, state="published", data=str_file)
File "build/bdist.linux-x86_64/egg/pytumblr/helpers.py", line 47, in add_dot_tumblr
return fn(_args, *_kwargs)
File "build/bdist.linux-x86_64/egg/pytumblr/init.py", line 387, in create_audio
return self._send_post(blogname, kwargs)
File "build/bdist.linux-x86_64/egg/pytumblr/init.py", line 509, in _send_post
return self.send_api_request("post", url, params, valid_options)
File "build/bdist.linux-x86_64/egg/pytumblr/init.py", line 542, in send_api_request
return self.request.post(url, params, files)
File "build/bdist.linux-x86_64/egg/pytumblr/request.py", line 61, in post
return self.post_multipart(url, params, files)
File "build/bdist.linux-x86_64/egg/pytumblr/request.py", line 111, in post_multipart
content = urllib2.urlopen(r).read()
File "/usr/lib64/python2.6/urllib2.py", line 126, in urlopen
return _opener.open(url, data, timeout)
File "/usr/lib64/python2.6/urllib2.py", line 391, in open
response = self._open(req, data)
File "/usr/lib64/python2.6/urllib2.py", line 409, in _open
'_open', req)
File "/usr/lib64/python2.6/urllib2.py", line 369, in _call_chain
result = func(*args)
File "/usr/lib64/python2.6/urllib2.py", line 1198, in https_open
return self.do_open(httplib.HTTPSConnection, req)
File "/usr/lib64/python2.6/urllib2.py", line 1162, in do_open
h.request(req.get_method(), req.get_selector(), req.data, headers)
File "/usr/lib64/python2.6/httplib.py", line 914, in request
self._send_request(method, url, body, headers)
File "/usr/lib64/python2.6/httplib.py", line 954, in _send_request
self.send(body)
File "/usr/lib64/python2.6/httplib.py", line 759, in send
self.sock.sendall(str)
File "/usr/lib64/python2.6/ssl.py", line 203, in sendall
v = self.send(data[count:])
File "/usr/lib64/python2.6/ssl.py", line 174, in send
v = self._sslobj.write(data)
TypeError: write() argument 1 must be string or read-only buffer, not bytearray

help me

hello
sorry i'm french
i can not run
I have an error on the test
I have my tumblr key, but I do not understand all

EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE

ERROR: test_blogInfo (main.TumblrRestClientTest)

Traceback (most recent call last):
File "/home/pi/pytumblr/pytumblr-master/tests/test_pytumblr.py", line 16, in setUp
with open('tests/tumblr_credentials.json', 'r') as f:
IOError: [Errno 2] No such file or directory: 'tests/tumblr_credentials.json'

=========--------------------------------------------------
Ran 33 tests in 0.335s

FAILED (errors=33)

Tags don't parse correctly?

The Tumblr API documentation says that the tags parameter for creating a new blog post should be of type String and contain Comma-separated tags for this post.

When I attempt to use the following:

client.create_photo(blogName, source='http://i.imgur.com/l6PpCfK.jpg', tags='dog,corgi,puppy')

It ends up like this on Tumblr:

screen shot 2013-07-28 at 1 21 57 pm

I've also tried it with spaces after the commas and with double quotes. Am I doing something wrong?

Pytumblr ignores the tweet parameter

I have the following code to post a blog on Tumblr through Tumblr API.

 post = client.create_text("xxx.tumblr.com",
                                      state="published",
                                      tags=utag_list,
                                      format='html',
                                      tweet=tweet.encode('utf-8'),
                                      slug=sluged_header,
                                      title=news.head_line.encode('utf-8'),
                                      body=body)
Strangely the tweet parameter doesnt do anything.

Looking at my blog source, I can see:

<li><a href="https://twitter.com/intent/tweet?text=Teenagers%20rescue%20elderly%20couple%20from%20sinking%20after%20car%20crashes%20into%20lake%20-%20Teenage%20wind-surfing...%20http%3A%2F%2Ftmblr.co%2FZ_F3uj1qlCL9u" class="share-item twitter" target="_blank">Tweet</a></li>

This is the default tweet message generated. Somehow my custom tweet message is completely ignored. And not generated in source. Hence the tweet sharing doesn't see the custom message. Any advice please?

why use oauth 1.0a instead of oauth2?

oauth1 is not well supported by python3, and I got errors when installing pytumblr. I am trying to fix by adding oauth2 support, but I'm not sure of my work process

Is there way to access the activity page for a user?

I'm looking for a way to determine how many notes a given post received through the user's blog. Currently I can count how many people reblogged a post from a given user, but I can't determine how to tell whether a like came from a specific blog or not. My work around for this was to look at the activity page and use that to determine how popular a given post was, but I don't see a way to access the activity page using the API.

Any thoughts?

Successful return

When calling an endpoint and receiving a 200, we should return the response subobject of the JSON rather than the whole body

Blog name niceness

When you call:

client.blog_info('seejohnrun')

you should get the same result as when calling:

client.blog_info('seejohnrun.tumblr.com')

We should just detect a . in the name and if it's missing, append .tumblr.com

create_link should support thumbnail too

If you look at https://www.tumblr.com/docs/en/api/v2#posting and go down to Link Posts, there is a "thumbnail" parameter, which is not accepted by this library. To get it accepted, modify __init__.py:

def _post_valid_options(self, post_type=None):
    ...
    elif post_type == 'link':
        valid += ['title', 'url', 'description', 'thumbnail']

And add 'thumbnail' to the valid list. Now if you create a link with a thumbnail, the thumbnail will also appear.

Reblog Function Parameters

I think there is a problem with the reblog function, am getting
TypeError: reblog() takes exactly 2 arguments (4 given)
when i add my username and this
File "/pytumblr/helpers.py", line 41, in add_dot_tumblr
if (len(args) > 1 and ("." not in args[1])):
TypeError: argument of type 'int' is not iterable
when i dont add a username.

Requests wait indefinitely (no timeout)

While iterating through posts, occasionally it will just sit... and sit... and sit... and sit...

By default, the httplib module that the oauth2 module uses has no timeout which means it will sit indefinitely. I'm not sure why nobody thought of this yet but why isn't there a default timeout set? I did it by creating a simple decorator and applying it to TumblrRequest().get().

Before signing my life away (CLA) and contributing my code, I thought I would bring this topic up and see if someone has already worked on this idea.

"type" param in get photo posts is not allowed

Why "type" is not allowed?

import pytumblr

client = pytumblr.TumblrRestClient('KEY')
client.posts('snow.tumblr.com', type='photo', limit=10)
---------------------------------------------------------------------------
Exception                                 Traceback (most recent call last)
...
Exception: type are not allowed fields

PS: PyTumblr==0.0.5

Unauthorized Error - Get The Number of Followers That A Blog Has

This is the JSON response, when I use this library to get the followers of a blog.

{'meta': {'status': 401, 'msg': 'Not Authorized'}, 'response': []}

This is what I use to call it:
#client is declared elsewhere tumblr_followers = json.loads(json.dumps(client.followers('good')))

print tumblr_followers

I am able to use the library for getting Blog Posts, I was just wondering how I could get the total number of followers of a blog, since apparently I am not authorized to get this info? Thanks.

Francois


After reading some documentation, it turns out you need OAuth, I'm still relatively new to Python, how do I make an OAuth request to Tumblr? I have the OAuth Consumer Key/Secret/API Key/Secret.

Thanks for the help in advance.

client.posts: Malformed JSON

I'm attempting to use client.posts() to retrieve a pseudo-mirror of my tumblr in order to echo them over to an associated twitter account.

My TumblrRestClient appears to be set up properly as client.info() or client.posts('metroidvanias') returns results.

As soon as I attempt to send a limit or offset, I get:

print(client.posts('metroidvanias', {'limit': 1}))
{'meta': {'status': 500, 'msg': 'Server Error'}, 'response': {'error': 'Malformed JSON or HTML was returned.'}}

Super python newb, so here are some other details:

  • Working in PyCharm
  • Python 2.7 interpreter being used
  • Manually created an api string that returns results in a browser, but aim is to gather the guts of all of my posts in 20-post chunks that the api appears to max out at

Any idea of where I'm going wrong with this?

Thanks, and best regards,
-Matt

How to solve "ascii" unicode errors?

While most of the posts that user copy paste runs fine however I can see lot of ascii errors at

resp = self.client.create_text(target_blog.id, title=post.title, body=post.content, tags=tags, date=post.date)

The error is in general with title or body.

UnicodeEncodeError: 'ascii' codec can't encode character u'\xa0' in position 622: ordinal not in range(128)

While I do try to " decode('utf-8', 'ignore') " but still in vain.
I get errors only from this library.

Any thoughts?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.