Giter VIP home page Giter VIP logo

imgurpython's People

Contributors

billputer avatar charley-peng avatar dorfsmay avatar jacobgreenleaf avatar jasdev avatar khazhyk avatar kodermike avatar mantazer avatar nateshoffner avatar poorlonesomecoder avatar randominsano avatar ueg1990 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

imgurpython's Issues

Adding Tests

I was thinking if we can add tests to the python library for Imgur API. To do this though, there are many options to consider. Since this an web API, results retrieved from requests will not always be the same. Some options to overcome this:

  1. Creating a test database from which to test the API calls. Imgur may not need to provide this
  2. Mocking up requests on which to run the API calls against? I know there is a mock library to Python that is used for that. I have never used it but if this a way to go I would like to give it a try
  3. Create test albums/images etc. using the POST requests, test them and check if result is as expected. Then test GET/DELETE request functions on them and check if result is as required. My concern with this is that not all functions will be tested
    Let me know what you think :)

subreddit_gallery return incorrect results

items = client.subreddit_gallery('Gaming', sort='time', window='week', page=0)
for item in items:
    print(item.link)

It returns results that are not correct, it has images uploaded in 2014 even

Trying to upload image

I am using python to upload image but the changes are not getting reflected.

My code:
client_id = "*_"
client_secret = "_
"
client = ImgurClient(client_id, client_secret)
authorization_url = client.get_auth_url('pin')
credentials = client.authorize('ba35e8a921', 'pin')
client.upload_from_path('/home/anubhav/Desktop/anubhav.jpeg', config=None, anon=True)

Can someone please help?

Replace id variables with non-keyword variable

It may be better to replace all variables named id because id is a keyword/function in python. For example in account.py, if you look at the code below:

class Account:

def __init__(self, id, url, bio, reputation, created, pro_expiration):
    self.id = id
    self.url = url
    self.bio = bio
    self.reputation = reputation
    self.created = created
    self.pro_expiration = pro_expiration

In self.id = id, id (not self.id) is the keyword that I am suggesting to replace. I have read somewhere that in some practices the variable name pk is used. Another alternative is _id. Hopefully only some files will need to be changed under imgur/models. Let me know what you think.

GalleryAlbum' object has no attribute 'images'

The API docs says that you can expect an Gallery Image OR Gallery Album when you call gallery. I get an error stating that "GalleryAlbum' object has no attribute 'images'" when I call the following code:

images = client.gallery(section='hot', sort='time', page=0, window='day', show_viral=True)
for image in images:
    thumbnail = 'http://i.imgur.com/' + image.id + 'b.jpg'

    if image.is_album and image.images_count > 0:
        thumbnail = 'http://i.imgur.com/' + image.images[0].id + 'b.jpg'

The API docs show that images is actually a valid attribute.

memes_subgallery_image raises ImgurClientError

The following snippet reproduces my problem:

client = imgurpython.ImgurClient(client_id, client_secret)
image_id = "1PeJC2R"
print(client.get_image(image_id)) # works fine
print(client.memes_subgallery_image(image_id)) # raises an error

The last call generates this output:

Traceback (most recent call last):
  File "<stdin>", line 5, in <module>
  File "/usr/lib/python3.4/site-packages/imgurpython/client.py", line 476, in memes_subgallery_image
    item = self.make_request('GET', 'g/memes/%s' % item_id)
  File "/usr/lib/python3.4/site-packages/imgurpython/client.py", line 161, in make_request
    raise ImgurClientError(response_data['data']['error'], response.status_code)
imgurpython.helpers.error.ImgurClientError: (400) Invalid Request.

I'm not too sure about Imgur, so excuse me if I'm wrong, but the API seems to use an image ID, so I figured it should be used here as well. Thanks!

raise ImgurClientError('JSON decoding of response failed.') imgurpython.helpers.error.ImgurClientError: JSON decoding of response failed.

What should I do when I get the following error in the middle of my running code? What's the cause for it?
http://stackoverflow.com/questions/40099046/raise-imgurclienterrorjson-decoding-of-response-failed-imgurpython-helpers

Traceback (most recent call last):
  File "download.py", line 14, in <module>
    search = imgur_client.gallery_search('cat', window='all', sort='time', page=i)
  File "/usr/local/lib/python2.7/dist-packages/imgurpython/client.py", line 531, in gallery_search
    response = self.make_request('GET', 'gallery/search/%s/%s/%s' % (sort, window, page), data)
  File "/usr/local/lib/python2.7/dist-packages/imgurpython/client.py", line 158, in make_request
    raise ImgurClientError('JSON decoding of response failed.')
imgurpython.helpers.error.ImgurClientError: JSON decoding of response failed.

My code is:

 12 imgur_client = ImgurClient(client_id, client_secret, access_token, refresh_token)
 13 for p in range(100, 500):
 14     search = imgur_client.gallery_search('cat', window='all', sort='time', page=p)
 15     for i in range(0, len(search)):
 16         #print(search[i].link)
 17         #print(dir(search[i]))
 18         print(search[i].type)
 19         if search[i].comment_count > 30 and search[i].type!='gif':
 20             count = 0
 21             image_file = urllib2.urlopen(search[i].link, timeout = 5)
 22             image_file_name = 'images/'+ search[i].id+search[i].type
 23             output_image = open(image_file_name, 'wb')
 24             output_image.write(image_file.read())
 25 
 26             for post in imgur_client.gallery_item_comments(search[i].id, sort='best'):
 27                 if count <= 30:
 28                     count += 1


Issue in Custom Gallery method get_custom_gallery

I get a key error on 'id' in the method get_custom_gallery:
Traceback (most recent call last):
File "/Users/ue/Desktop/Projects/imgur-cli/imgur_cli/cli.py", line 155, in main
imgur_cli.main(sys.argv[1:])
File "/Users/ue/Desktop/Projects/imgur-cli/imgur_cli/cli.py", line 147, in main
args.func(self.client, args)
File "/Users/ue/Desktop/Projects/imgur-cli/imgur_cli/cli_api.py", line 190, in cmd_custom_gallery_items
args.window, args.page)
File "/Users/ue/.virtualenvs/imgur-cli/lib/python3.4/site-packages/imgurpython/client.py", line 362, in get_custom_gallery
gallery['id'],
KeyError: 'id'

Apparently these are the only keys that are returned: ['link', 'account_url', 'item_count', 'items', 'tags']

Expose ETags in requests for performance

From the API page Performance Tips, on allowing you to avoid downloading redundant information.

It would be nice if I could make a request like response = client.subreddit_gallery(name, etag="a695f4e9672bf7fc7a779ac12ead684d72292506") that would set the If-None-Match header, and be able to get response.etag on responses.

pep-8

Please consider using underscored_names rather than camel case for function names.

Callback for large file upload

Hi, i am requiring a way to upload (large) files (without loading them all into the memory) via the API and have an status callback which calls at every written chunk (update progress bar).
The only way i found to do this via requests is using a multipart message.
The python module requests_toolbelt for example supports this, but the encoding part isn't that complex, so it could be done without additional required libs, too (FE, see end of this article: http://blog.thesparktree.com/post/114053773684/the-unfortunately-long-story-dealing-with ).

The problem with this approach is we need to set the content_type. imgurpythons Client.make_request function doesn't support setting headers.
So i suggest adding a new function to imgurpython supporting streaming uploads with callbacks and add the code from Client.make_request, or (and i think this is the better way) add an "additional headers" parameter to Client.make_request which updates the headers returning from the prepare_headers call and just use Client.make_request in the new "streaming_upload_file_" function.

A short example using requests_toolbelt with the additional_header approach: https://gist.github.com/SleepProgger/a6ca9cc15e3277f4e17a

I think such feature would be nice to have in the library, so let me know what you think about it.
I would be willing to submit a patch if the changes are wanted.

RATE LIMIT

hey,
1250 images per day is the current rate limit.

is there any way to include a "sleep" thing so it uploads after 24 hours again to not get blocked ?

Add license

Please add a license to the project.

It would be nice if you chose BSD or MIT ;)

Request: example of command-line authentication

I would like to write a small command-line program to upload several hundred files extracted from an old WordPress blog. I've read this library's docs and the Imgur API docs, but still don't understand how to authenticate (I don't have a URL to redirect to for obtaining a PIN). Can the examples please include one showing how to authenticate from the command line starting with just a client ID and client secret?

upload_from_path does not close the file

as can be seen from the following snippet:

def upload_from_path(self, path, config=None, anon=True):
if not config:
config = dict()
fd = open(path, 'rb')
contents = fd.read()
b64 = base64.b64encode(contents)
data = {
'image': b64,
'type': 'base64',
}
data.update({meta: config[meta] for meta in set(self.allowed_image_fields).intersection(config.keys())})
return self.make_request('POST', 'upload', data, anon)

The file needs to be closed after being opened. The code above can be easily changed into the following:

def upload_from_path(self, path, config=None, anon=True):
    if not config:
        config = dict()

    with open(path, 'rb') as fd:
        contents = fd.read()
    b64 = base64.b64encode(contents)

    data = {
        'image': b64,
        'type': 'base64',
    }

    data.update({meta: config[meta] for meta in set(self.allowed_image_fields).intersection(config.keys())})
    return self.make_request('POST', 'upload', data, anon)

And the issue will be fixed. The issue is that a BufferedReader is left open and never closed.

Automatic authorization

Hi,

I was wondering how do an automatic authorization from within the code.

In the README I can see:

# ... redirect user to `authorization_url`, obtain pin (or code or token) ...

But I want to grab the pin automatically, since the authorization url redirects me to the actual url with the pin I am not sure how to follow that stream since the requests library only follows on POST/GET/DELETE methods.

My app has no user interface, I need to get the pin from the code, with no human interaction.
Any suggestions?

Thanks!

url with '+' causing issues.

I found this bug, and submitted this to the [email protected].

It appears to be an issue within the website and how it parses the url, as it's replicated by copy and pasting the image url to the homepage and doesn't happen when you save the image and drag image.

The specific call I'm using within python:
self.client.upload_from_url(url, config=None, anon=False)
example url:
https://static1.squarespace.com/static/50ae6cdfe4b09793f627a63b/t/5170a86ee4b09a3e33b049df/1366337647067/chicken+legs.jpg
exception message from cli:
imgurpython.helpers.error.ImgurClientError: (415) {'code': 1003, 'message': 'File type invalid (1)', 'type': 'ImgurException', 'exception': {}}
Inline image 2

Remove method set_user_auth

This method is not used anywhere and self.auth is defined during instantiating ImgurClient. So should it be removed?

Request for non-blocking call

Hello. I would like to request a Non Blocking method for the python imgur API wrapper. Currently because of the underlying Requests library, it causes my program to hang up for the duration of the call. A library like aiohttp will be really good.

Register API url link broken.

"You must register your client with the Imgur API, and provide the Client-ID" url link for registering a client ID is broken.

Upload image without PIN

Hi awesome Imgurians,

I'm making an app where the final step is an image upload to Imgur. However, I want that to go automatically i.e without entering a PIN code.

Is that possible?

Get account favourites

I guess there is a problem with the method get_account_favorites. When i try to get all favourites, i only get the images on the first page.
This is my code after authentication:

imgs = client.get_account_favorites(username)
    for index, img in enumerate(imgs["data"]):
       print "Loading " + str(index) + " from " + str(len(imgs["data"]))
       if img["type"]:
           if img["type"] == "image/gif":
               urllib.urlretrieve(img["gifv"], str(index) + ".gif")
           else:
              urllib.urlretrieve(img["link"], str(index) +".jpg")

I already tried to change the method implemenation to this version, without the page parameter. But this doesnt work, too.

def get_account_favorites(self, username):
        self.validate_user_context(username)
        favorites = self.make_request('GET', 'account/%s/favorites/' % username)

        return build_gallery_images_and_albums(favorites)

Maybe there is a problem with the api or i have made a failure in my code?
Thanks.

Allow permanent access to program

Is there a way to allow a program to upload images on an account without requiring manual authorization from the user every time? The following code (heavily based on the example code) requires the user to allow access each time:

imgur = ImgurClient(IMGUR_CLIENT_ID, IMGUR_CLIENT_SECRET)
print(imgur.get_auth_url('pin'))
credentials = imgur.authorize(input("pin: "), 'pin')
imgur.set_user_auth(credentials['access_token'], credentials['refresh_token'])

Is there a way around this? I could login to a hidden browser instance using the plaintext login details, but that doesn't seem that secure to me...

Configuration file format

Please consider using e.g. ConfigParser for the configuration file rather than json. Json does not allow comments and trailing commas.

Submit Already Uploaded Image to Gallery?

I'm trying to automatically submit an image to the gallery after I upload it via URL, but I'm not sure exactly how. My upload code is:

from auth import authenticate


i = authenticate()

album = None 

title = 'Test Title'
description = 'Test Description: '
image_path = 'http://animal-dream.com/data_images/goose/goose2.jpg'

config = {
    'album': album,
    'name': title,
    'title': title,
    'description': description
}

print("Uploading image to Imgur... ")
image = i.upload_from_url(image_path, config=config, anon=False)
print("Imgur image posted at: {0}".format(image['link']))

I've found a link here, which explains how to do this with the json library, but I'm having issues merging the two. Using what I have above, can I somehow send a request to submit my image to the community?

imgurpython.helpers.error.ImgurClientRateLimitError: Rate-limit exceeded!

I have the following error:

/usr/local/lib/python2.7/dist-packages/requests/packages/urllib3/util/ssl_.py:90: InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. For more information, see https://urllib3.readthedocs.org/en/latest/security.html#insecureplatformwarning.
  InsecurePlatformWarning
/usr/local/lib/python2.7/dist-packages/requests/packages/urllib3/util/ssl_.py:90: InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. For more information, see https://urllib3.readthedocs.org/en/latest/security.html#insecureplatformwarning.
  InsecurePlatformWarning
Traceback (most recent call last):
  File "download.py", line 22, in <module>
    search = imgur_client.gallery_search('cat', window='all', sort='time', page=p)
  File "/usr/local/lib/python2.7/dist-packages/imgurpython/client.py", line 531, in gallery_search
    response = self.make_request('GET', 'gallery/search/%s/%s/%s' % (sort, window, page), data)
  File "/usr/local/lib/python2.7/dist-packages/imgurpython/client.py", line 153, in make_request
    raise ImgurClientRateLimitError()
imgurpython.helpers.error.ImgurClientRateLimitError: Rate-limit exceeded!

for this code:

  1 from imgurpython import ImgurClient
  2 import inspect
  3 import random
  4 import urllib2
  5 import requests
  6 from imgurpython.helpers.error import ImgurClientError
  7 
  8 client_id = "ABC"
  9 client_secret = "ABC"
 10 access_token = "ABC"
 11 refresh_token = "ABC"
 12 
 13 
 14 
 15 image_type = ['jpg', 'jpeg']
 16 
 17 imgur_client = ImgurClient(client_id, client_secret, access_token, refresh_token)
 18 
 19 item_count = 0
 20 for p in range(1, 10000):
 21     try:
 22         search = imgur_client.gallery_search('cat', window='all', sort='time', page=p)
 23         for i in range(0, len(search)):
 24             item_count +=1
 25             print(search[i].comment_count)
 26             if search[i].comment_count > 10 and not search[i].is_album:
 27                 print(search[i].type)
 28                 if search[i].type[6:] in image_type:
 29                     count = 0
 30                     try:
 31                         image_file = urllib2.urlopen(search[i].link, timeout = 5)
 32                         image_file_name = 'images/'+ search[i].id+'.'+search[i].type[6:]
 33                         output_image = open(image_file_name, 'wb')
 34                         output_image.write(image_file.read())
 35                         for post in imgur_client.gallery_item_comments(search[i].id, sort='best'):
 36                             if count <= 10:
 37                                 count += 1
 38                         output_image.close()
 39                     except urllib2.URLError as e:
 40                         print(e)
 41                         continue
 42                     except socket.timeout as e:
 43                         print(e)
 44                         continue
 45                     except socket.error as e:
 46                         print(e)
 47                         continue
 48     except ImgurClientError as e:
 49         print(e)
 50         continue
 51 
 52 print item_count


Also I see this line almost very often:

/usr/local/lib/python2.7/dist-packages/requests/packages/urllib3/util/ssl_.py:90: InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. For more information, see https://urllib3.readthedocs.org/en/latest/security.html#insecureplatformwarning.
  InsecurePlatformWarning

How can I fix the error? Is there any workaround for rate limit error in Imgur?
Also here's my credit info:

User Limit: 500
User Remaining: 500
User Reset: 2016-10-18 14:32:41
User Client Limit: 12500
User Client Remaining: 9570

[API] [Feature] Uploading small videos for recording

I would request a feature be added to the API, regarding this Imgur feature.

Imgur downloads the videos from their URL anyways, to process them..... why can't small videos be uploaded through the API? Surely this shouldn't add any strain or risk that people using URLs wouldn't also add. Namely, I'm requesting this for programs like ShareX. When I use ShareX to record a 5-10 second clip, it would be nice to upload it easily through your vgif system, like I do my screenshots.

ImgurClient().authorize() does not work when using authorization codes to request tokens

The Imgur authorization API docs indicate that that you can request a response_type of code to return an authorization code to obtain a pair of access and refresh tokens. After I receive the code, I try to pass it the Imgur API using ImgurClient.authorize():

>>> from imgurpython import ImgurClient
>>> import my_keys
>>> client = ImgurClient(my_keys.client_id, my_keys.client_secret)
>>> client.authorize('AUTHORIZATION_CODE_HERE', grant_type='authorization_code')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python2.7/site-packages/imgurpython/client.py", line 103, in authorize
    }, True)
  File "/usr/local/lib/python2.7/site-packages/imgurpython/client.py", line 152, in make_request
    raise ImgurClientError(response_data['data']['error'], response.status_code)
imgurpython.helpers.error.ImgurClientError: (400) Missing parameter. "code" is required

This appears to be an inconsistency in ImgurClient and the API, since the grant_type parameter that gets passed to the token request endpoint is authorization_code but the parameter name for the code value itself is code, rather than authorization_code (which is what gets passed by ImgurClient().authorize()).

JSON decoding of response failed after trying client.upload_from_path()

I am trying to upload this gif back to imgur using

try:
        print("Uploading image... ")
        imageURL = client.upload_from_path('hlN3NZZ.gif', config=None, anon=False)
    except ImgurClientError as e:
        print(e.error_message)
        print(e.status_code)

However I keep getting:

JSON decoding of response failed.
None

Could it be due to the large size of the gif?

Submit imgur-python to PyPi

I would really appreciate it if you submitted this library to PyPi! That way otheres can use imgur-python with pip. Thank you!

OAuth is very inconvenient

OAuth is very inconvenient for certain cases. For example, I have a 5-line Python script in my /bin/ directory that I can use to upload an image from the command line quickly. However, since I need to go through the whole OAuth flow to upload as myself, I need to be visiting the website every single time I want to upload an image, or upload the image without having it go to my page, or take care to store the state somewhere.

All of these options are very onerous, all I want to do is go to my settings page, find an API key and paste it in the script and have it work forever. Is there a way to do that?

Uploading URLs ending with two '@'s does not work

I'm using Flask to upload images from imdb to Imgur and have noticed that only URLs ending with one '@' will work while having two '@'s will cause a problem ("500 error: cannot process upload!"). This is using the upload_from_url method

These work:
http://ia.media-imdb.com/images/M/MV5BMjMzMjIxOTIxMl5BMl5BanBnXkFtZTgwNTk4NDI0NjE@._V1_.jpg

http://ia.media-imdb.com/images/M/MV5BMTg4MzYwNDI3NF5BMl5BanBnXkFtZTgwNzUyMTc1NjE@._V1_.jpg

These don't:
http://ia.media-imdb.com/images/M/MV5BOTk1OTA1MjIyNV5BMl5BanBnXkFtZTcwODQxMTkyMQ@@._V1_.jpg

http://ia.media-imdb.com/images/M/MV5BMjAzNTk4NTc1N15BMl5BanBnXkFtZTcwOTI0NjAwMQ@@._V1_.jpg

http://ia.media-imdb.com/images/M/MV5BMTI0MzkyNDM4Ml5BMl5BanBnXkFtZTcwMzMyOTQyMQ@@._V1_.jpg

I can upload these URLs manually through the website, though.

get_image(id) doesn't fetch account_url.

Hi,

I have noticed that the get_image method doesn't fetch account_url properly. Possibly with even other functions, which I haven't tested yet.

Expected would've been 'undercovergiraffe' in thi example:

>>> from imgurpython import ImgurClient
>>> client = ImgurClient(client_id, client_secret)
>>> print vars(client.get_image('f1Y1xzl'))
{'height': 349, 'datetime': 1426207261, 'looping': True, 'bandwidth': 49785848969979L, 'nsfw': False, 'vote': None, 'id': u'f1Y1xzl', 'description': u'I love that he tries to steal the hose', 'title': u'Clumsy baby elephant loves bath time', 'section': None, 'width': 633, 'size': 97949459, 'type': u'image/gif', 'account_id': 1373582, 'views': 508281, 'link': u'http://i.imgur.com/f1Y1xzlh.gif', 'webm': u'http://i.imgur.com/f1Y1xzl.webm', 'gifv': u'http://i.imgur.com/f1Y1xzl.gifv', 'favorite': False, 'mp4': u'http://i.imgur.com/f1Y1xzl.mp4', 'account_url': None, 'animated': True}

Uploading an ~35mb gif throws JSONDecodeError

So I am trying to uplaod a gif using the upload_from_path function. This works for small gifs, but when I try to upload a larger one I get the following error:

Traceback (most recent call last):
  File "C:\Program Files\Anaconda3\lib\site-packages\imgurpython\client.py", line 156, in make_request
    response_data = response.json()
  File "C:\Program Files\Anaconda3\lib\site-packages\requests\models.py", line 808, in json
    return complexjson.loads(self.text, **kwargs)
  File "C:\Program Files\Anaconda3\lib\json\__init__.py", line 319, in loads
    return _default_decoder.decode(s)
  File "C:\Program Files\Anaconda3\lib\json\decoder.py", line 339, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "C:\Program Files\Anaconda3\lib\json\decoder.py", line 357, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\richard\Desktop\imgur_test.py", line 62, in <module>
    response = upload(file_name)
  File "C:\Users\richard\Desktop\imgur_test.py", line 44, in upload
    return imgur.upload_from_path(file_name)
  File "C:\Program Files\Anaconda3\lib\site-packages\imgurpython\client.py", line 596, in upload_from_path
    return self.make_request('POST', 'upload', data, anon)
  File "C:\Program Files\Anaconda3\lib\site-packages\imgurpython\client.py", line 158, in make_request
    raise ImgurClientError('JSON decoding of response failed.')
imgurpython.helpers.error.ImgurClientError: JSON decoding of response failed.
[Finished in 37.0s with exit code 1]

Reproduction code:

import urllib.request, shutil
from imgurpython import ImgurClient

imgur_client_id = 'client_id'
imgur_client_secret = 'client_secret'
imgur = ImgurClient(imgur_client_id, imgur_client_id)

def download_file(url, file_name):
    with urllib.request.urlopen(url) as response, open(file_name, 'wb') as out_file:
        shutil.copyfileobj(response, out_file)

def upload(file_name):
    return imgur.upload_from_path(file_name)

if __name__ == '__main__':
    url = 'http://i.imgur.com/h3qtAz9.gif'
    file_name = 'test.gif'
    print("starting download")
    download_file(url, file_name)
    print("download complete\nstarting upload")
    response = upload(file_name)
    print("upload complete")

client.get_account_albums('me') does not return all albums

When I run client.get_account_albums('me') I don't get all albums.

And I can't even figure out anything that stands out about albums that are not returned. It returns all trypes of albums - public, hidden and secret - so I'm logged in correctly. Some albums just dont show up. There are no illegal characters in album titles as well.

Out of 100+ albums I only get 49.

What may be the cause of it?

ImgurClientError (500) when uploading from path

When trying to run

from imgurpython import ImgurClient

client_id = "XXXXXXXXXXXXXX"
client_secret = "XXXXXXXXXXXXXX"
access_token = "XXXXXXXXXXXXXX"
refresh_token = "XXXXXXXXXXXXXX"
imgur_client = ImgurClient(client_id, client_secret, access_token, refresh_token)

imgur_client.upload_from_path(event.pathname, config={"album":"azXrnwH"}, anon=False) 

the following exception results:


 File "imgupload.py", line 25, in ........
    imgur_client.upload_from_path(event.pathname, config={"album":"azXrnwH"}, anon=False)
  File "/root/.pyenv/versions/3.6.0/lib/python3.6/site-packages/imgurpython/client.py", line 596, in upload_from_path
    return self.make_request('POST', 'upload', data, anon)
  File "/root/.pyenv/versions/3.6.0/lib/python3.6/site-packages/imgurpython/client.py", line 161, in make_request
    raise ImgurClientError(response_data['data']['error'], response.status_code)
imgurpython.helpers.error.ImgurClientError: (500) {'code': 1001, 'message': 'File was not uploaded correctly', 'type': 'Exception_Logged', 'exception': {}}

Is there a way to get more information about this error?

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.