damgaard / pyimgur Goto Github PK
View Code? Open in Web Editor NEWThe simple way of using Imgur.
License: GNU General Public License v3.0
The simple way of using Imgur.
License: GNU General Public License v3.0
Just opening this as a clean issue thread. Problem is that PyImgur
package can not be installed on Linux through PyPI.
Full debug is as follows.
(env)james@blackbox:/tmp/test$ pip install pyimgur-0.3.2.tar.gz --verbose
Unpacking ./pyimgur-0.3.2.tar.gz
Running setup.py egg_info for package from file:///tmp/test/pyimgur-0.3.2.tar.gz
Traceback (most recent call last):
File "<string>", line 14, in <module>
File "/tmp/pip-t98d8G-build/setup.py", line 10, in <module>
INIT = open(os.path.join(HERE, PACKAGE_NAME, '__init__.py')).read()
IOError: [Errno 2] No such file or directory: '/tmp/pip-t98d8G-build/pyimgur/__init__.py'
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "<string>", line 14, in <module>
File "/tmp/pip-t98d8G-build/setup.py", line 10, in <module>
INIT = open(os.path.join(HERE, PACKAGE_NAME, '__init__.py')).read()
IOError: [Errno 2] No such file or directory: '/tmp/pip-t98d8G-build/pyimgur/__init__.py'
----------------------------------------
Command python setup.py egg_info failed with error code 1 in /tmp/pip-t98d8G-build
Exception information:
Traceback (most recent call last):
File "/tmp/test/env/lib/python2.7/site-packages/pip-1.1-py2.7.egg/pip/basecommand.py", line 104, in main
status = self.run(options, args)
File "/tmp/test/env/lib/python2.7/site-packages/pip-1.1-py2.7.egg/pip/commands/install.py", line 245, in run
requirement_set.prepare_files(finder, force_root_egg_info=self.bundle, bundle=self.bundle)
File "/tmp/test/env/lib/python2.7/site-packages/pip-1.1-py2.7.egg/pip/req.py", line 1009, in prepare_files
req_to_install.run_egg_info()
File "/tmp/test/env/lib/python2.7/site-packages/pip-1.1-py2.7.egg/pip/req.py", line 225, in run_egg_info
command_desc='python setup.py egg_info')
File "/tmp/test/env/lib/python2.7/site-packages/pip-1.1-py2.7.egg/pip/__init__.py", line 256, in call_subprocess
% (command_desc, proc.returncode, cwd))
InstallationError: Command python setup.py egg_info failed with error code 1 in /tmp/pip-t98d8G-build
pip.log
contains the same info. Some previous discussion is here #5
I am trying to use this API for commercial usage, so I followed the steps in the readme.md: https://github.com/Damgaard/PyImgur#mashape-api
I then get this error: HTTPSConnectionPool(host='imgur-apiv3.p.mashape.com', port=443): Max retries exceeded with url: /3/image (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x7f7cb9afb430>: Failed to establish a new connection: [Errno -2] Name or service not known'))
The problem is occurring because imgur switched from using mashape to using rapidapi for commercial usage (see new docs here
The solution is to replace the endpoint with imgur-apiv3.p.rapidapi.com and the mashape_key with the X-RapidAPI-Key.
Change this code this code to raise an exception instead of printing to stdout
if not resp.ok:
try:
error_msg = "Imgur ERROR message: {}".format(content['error'])
print(error_msg)
print("-" * len(error_msg))
except Exception:
pass
resp.raise_for_status()
eg:
if not resp.ok:
try:
raise ImgurException("Imgur ERROR message: {}".format(content['error']))
except Exception:
resp.raise_for_status()
Potentially I'm just being dumb, but I'm running into this weird situation where the PyImgur is able to upload 2 or so images and then it starts complaining that I have the wrong client ID.
I tried slowing it down thinking I was hitting Imgur's API limit, but even at 10 second delays, it still pops up. I don't see any warning from Imgur that my client ID is bad, so I'm not sure what's going on...
Traceback (most recent call last):
File "", line 76, in
main()
File "", line 70, in main
link = ImgurBatch(files)
File "", line 57, in ImgurBatch
links.append(imgurupload(item))
File "", line 24, in imgurupload
uploaded_image = im.upload_image(PATH, title="")
File "C:\Users\Bram\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pyimgur_init_.py", line 1150, in upload_image
resp = self._send_request(self.base_url + "/3/image",
File "C:\Users\Bram\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pyimgur_init.py", line 731, in _send_request
result = request.send_request(url, verify=self.verify, **kwargs)
File "C:\Users\Bram\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pyimgur\request.py", line 102, in send_request
resp.raise_for_status()
File "C:\Users\Bram\AppData\Local\Programs\Python\Python38-32\lib\site-packages\requests\models.py", line 941, in raise_for_status
raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 403 Client Error: Permission Denied for url: https://api.imgur.com/3/image
Hello, I'm trying to add some images to an album anonymously, using the images delete hashes. Since I'm doing this without the use of an account, I have no need to authenticate with an access code, and therefore can't add these images. Can checks be added to see if the user is doing things anonymously, because this is really breaking my project.
I've been using the following code to upload PNGs to imgur:
im = pyimgur.Imgur(CLIENT_ID)
uploaded_image = im.upload_image(PATH, title=PLOTNAME)
But when going on my imgur account and going on my submitted images, there are no images. Why is this?
Whats the preferred way to run tests? I think tests should also be included in the source dist, btw, esp for packaging..
In Imgur's documentation, you are able to specify the an integer that represents the number of the paginated gallery. PyImgur does not offer an argument for the page number, and I'm in need of this functionality at the moment.
https://api.imgur.com/endpoints/gallery#subreddit
Perhaps update the function like so:
def get_subreddit_gallery(self, subreddit, sort='time', window='top',
limit=None, page=0):
"""
Return a list of gallery albums/images submitted to a subreddit.
A subreddit is a subsection of the website www.reddit.com, where users
can, among other things, post images.
:param subreddit: A valid subreddit name.
:param sort: time | top - defaults to top.
:param window: Change the date range of the request if the section is
"top", day | week | month | year | all, defaults to day.
:param limit: The number of items to return.
:param page: The page number of the gallery
"""
url = (self._base_url + "/3/gallery/r/{0}/{1}/{2}/{3}".format(
subreddit, sort, window, page))
resp = self._send_request(url, limit=limit)
return [_get_album_or_image(thing, self) for thing in resp]
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?
Hello, I'm currently writing a little script that will pull imgur links from a IRC channel and store them in a database. I would also like to print the title to the channel.
Problem is, imgur's IDs are pretty ambiguous. An ID can represent several things: a image, an album, a gallery, a picture in a gallery or even a gallery album. It seems like you can go to imgur.com/[id here] and it will happily show you whatever thing that exists on that ID, whether it's an album, a image and so on.
So, apart from doing multiple try/except blocks to get the title and link (which are the only things I'm interested in), are there any nice ways of doing this with PyImgur? It would be terrific if I could just do one request that would get all the things that IDs may have in common, where title and link is from what I gather among those.
Hello there. It is possible totally unrelated to PyImgut question, but still. Any time i try to use my script with pyimgur from the console, using python interpreter it's working flawlessly. But when i try to bundle same script using PyInstaller, i got "SSLError: [Errno 185090050] _ssl.c:344: error:0B084002:x509 certificate routines:X509_load_cert_crl_file:system lib".
Sorry if it's completely unrelated.
Great stuff you made :) I want to upload images (one at a time) to the same album without having to enter the PIN every time.
Is this achievable? (it would save my life!)
Thanks!
This image give me an error, when uploading:
File "C:\Users\.venv\lib\site-packages\pyimgur\__init__.py", line 1141, in upload_image
with open(path, 'rb') as image_file:
OSError: [Errno 22] Invalid argument: 'https://i.gr-assets.com/images/S/compressed.photo.goodreads.com/books/1615432462l/56589778.jpg''
what could it be?
There is actually no need to encode an image into b64, it will increase the picture size.
I've added new argument to upload_image funtion, to directly push an image without opening a file
patch: http://paste.org/66501
I got client_id, client_secret, access_token, and refresh_token just fine. Other user functions like user.name or user.get_comments() etc work fine but when I call user.get_notifications() it throws this error
File "/Library/Python/2.7/site-packages/pyimgur/__init__.py", line 1353, in get_notifications com_dict in resp['replies']] UnboundLocalError: local variable 'msg_dict' referenced before assignment
Working on a project that involves uploading mp4 files to imgur, attempting to do it using this causes some kind of very long error. Is there a way to use this project for mp4s or is it simply not supported?
I'm trying add an image to an album using the images url with the following snippet
pyimgur.oauth_set_credentials(IMGUR_CONSUMER_KEY,IMGUR_CONSUMER_SECRET,token,secret)
pyimgur.edit_album("ALBUMID",add_images=["http://URLTOIMAGE.jpg"])
but it refuses to work, am I using the function correctly?
Awesome module. I've been trying to build an easy way to move all my imgur favorites between different photo sharing sites. I know the API call https://api.imgur.com/3/account/%s/gallery_favorites defaults to just page 0 with 60 images, but is there any way to iterate over all pages with PyImgur?
I know that when I access the API directly you can just iterate over a big enough number to access every page (IE https://api.imgur.com/3/account/me/gallery_favorites/0..25 or whatever page) but I can't see how to do that with PyImgur, any advice?
I'm pretty new to Python, but have plenty of experience in php and ruby, using your module to help learn so thanks =D
Python 3 should be added to setup.py
specifiers and also in pypi metadata.
I'm getting the following error:
Imgur ERROR message: {'code': 429, 'message': 'You are uploading too fast. Please wait 37 more minutes.', 'type': 'ImgurException', 'exception': []}
----------------------------------------------------------------------------------------------------------------------------------------------------
Is there a api to catch this 429 Too Many Requests
with the time to wait in seconds as a property?
I keep getting a 400 error, with the following code:
img = pyimgur.upload_image('screenshot.png', title='Screenshot', api_key='76c8c84eaa7c685')
It says when parameters are out of bounds or image upload fails, but I manually uploaded the exact image and it worked fine. Not sure what is going on.
I think that at pyimgur/init.py:798 there should be 'code':code instead of 'pin':code.
It throws HTTPError: 400 Client Error: Bad Request and seems to work fine after the change.
File "C:\Users\Jason\Documents\Programming\e-card-websocket\socket.py", line 4, in <module>
from pyimgur import Imgur
File "C:\Users\Jason\AppData\Local\Programs\Python\Python36\lib\site-packages\pyimgur\__init__.py", line 45, in <module>
import requests # NOQA
File "C:\Users\Jason\AppData\Local\Programs\Python\Python36\lib\site-packages\requests\__init__.py", line 43, in <module>
import urllib3
File "C:\Users\Jason\AppData\Local\Programs\Python\Python36\lib\site-packages\urllib3\__init__.py", line 8, in <module>
from .connectionpool import (
File "C:\Users\Jason\AppData\Local\Programs\Python\Python36\lib\site-packages\urllib3\connectionpool.py", line 7, in <module>
from socket import error as SocketError, timeout as SocketTimeout
ImportError: cannot import name 'error'
I get this. I don't know how to fix it.
The get_gallery() function is not working. It seems that the constructor of Gallery_album has no argument "has_fetched". I am using version 0.5.2
Callstack:
im.get_gallery()
Traceback (most recent call last):
File "", line 1, in
File "/usr/lib/python2.7/site-packages/pyimgur/init.py", line 920, in get_gallery
return [_get_album_or_image(thing, self) for thing in resp]
File "/usr/lib/python2.7/site-packages/pyimgur/init.py", line 59, in _get_album_or_image
return Gallery_album(json, imgur, has_fetched=False)
TypeError: init() got an unexpected keyword argument 'has_fetched'
When you upload an image as anon user using imgur web, you get the link to delete the image. With PyImgur, is it possible to get the delete link?
Edit: Found the answer. Yes it is possible, use the "deletehash" method
Using Python 2.7.5 on Arch Linux 3.11.6.
Commit: fee5db0
When authenticating using the PIN method:
Traceback (most recent call last):
File "./uploader.py", line 84, in <module>
t = UploadThread()
File "./uploader.py", line 36, in __init__
self.__auth()
File "./uploader.py", line 42, in __auth
self.__imgur.exchange_pin(pin)
File "/usr/lib/python2.7/site-packages/pyimgur/__init__.py", line 805, in exchange_pin
data_field=None)
File "/usr/lib/python2.7/site-packages/pyimgur/__init__.py", line 704, in _send_request
result = request.send_request(url, **kwargs)
File "/usr/lib/python2.7/site-packages/pyimgur/request.py", line 91, in send_request
content = resp.json()
TypeError: 'dict' object is not callable
Fixed this by changing line 91 of request.py
to
content = resp.json
since resp.json
is an attribute, not a function. I'll gladly provide a patch but I don't know the proper way to go about it.
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?
The source of __ init __.py served from https://pypi.python.org/packages/source/p/pyimgur/pyimgur-0.5.2.tar.gz is different than the source from here. In the package from PyPI is a bug that doesn't let me fetch a gallery.
urlparse was renamed to urllib.parse in Python 3, issue is raising import errors.
Can a feature be added for pyimgur to read from stdin when path is a dash "-"?
would be useful for something like:
qrencode -t PNG "https://somesite.xyz" -o - | python mypynvim.py -
This snippet of code:
picgallery = im.get_subreddit_gallery("pics")
is raising this error:
requests.exceptions.HTTPError: 404 Client Error: Not Found
I'm following the documentation perfectly, so I'm puzzled as to why this isn't working.
Hi! First off I want to thank you @Damgaard for creating an amazingly easy-to-use Python package for the Imgur API.
I am writing this issue today suggesting you reconsider relicensing your code under LGPLv3 so my little project and other differently licensed projects may enjoy the results of your open source contribution. As the sole copyright holder you have the right to relicense your work in upcoming releases/commits (see this StackOverflow question for details).
Some more information on the issue:
Hi, I'm trying to authenticate my imgur account via PyImgur, but I don't see anything in the docs about it.
Is there a way to get a list of images for an album-url of the type http://[account_name].imgur.com/[weird_long_album_hash]?
The info at https://pypi.python.org/pypi/pyimgur/0.5.2 is still outdated. Please consider changing it. Even the upload example uses wrong variables in IMAGE
class.
If possible, how can I upload an image url?
I'm trying the basic example to upload a picture to imgur, but whenever I get to the attributes like data, url, link, i get AttributeError: Image instance has no attribute 'date'.
Here is the code I have
import pyimgur
CLIENT_ID = ""
PATH = "/Users/jacksongeller/Desktop/imgur/sample.png"
im = pyimgur.Imgur(CLIENT_ID)
uploaded_image = im.upload_image(PATH, title="Uploaded with PyImgur")
print(uploaded_image.title)
print(uploaded_image.date)
print(uploaded_image.url)
print(uploaded_image.link)
here is the error
$ python main.py
Uploaded with PyImgur
Traceback (most recent call last):
File "main.py", line 11, in <module>
print(uploaded_image.date)
File "/Library/Python/2.7/site-packages/pyimgur/__init__.py", line 70, in __getattr__
(type(self).__name__, attribute))
AttributeError: Image instance has no attribute 'date'
Am I missing something basic? or a syntax error? I cannot seem to figure it out. Thanks in advance. great module by the way
I am trying to access all albums from my authenticated user as below(python=2.7). Other pyimgur.User methods such as get_statistics() ran without issue.
import pyimgur
CLIENT_ID = "**********"
CLIENT_SECRET = "****************"
im = pyimgur.Imgur(CLIENT_ID, CLIENT_SECRET, refresh_token="***********")
im.refresh_access_token()
#album=im.create_album("An authorized album", "Cool stuff!")
user=im.get_user("************")
print(user)
print(user.get_images())
Traceback (most recent call last):
File "main.py", line 15, in <module>
print(user.get_images()) File "/home/runner/.local/share/virtualenvs/python2/lib/python2.7/site-packages/pyimgur/__init__.py", line 1347, in get_images
resp = self._imgur._send_request(url, limit=limit) File "/home/runner/.local/share/virtualenvs/python2/lib/python2.7/site-packages/pyimgur/__init__.py", line 731, in _send_request
result = request.send_request(url, verify=self.verify, **kwargs) File "/home/runner/.local/share/virtualenvs/python2/lib/python2.7/site-packages/pyimgur/request.py", line 102, in send_request
resp.raise_for_status() File "/home/runner/.local/share/virtualenvs/python2/lib/python2.7/site-packages/requests/models.py", line 940, in raise_for_status
raise HTTPError(http_error_msg, response=self)requests.exceptions.HTTPError: 400 Client Error: Bad Request for url: https://api.imgur.com/3/account/NeverLucky135/images/%7B%7D
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.