I'm trying to make a Reddit bot, except I cannot even use the following simple example, nor the examples PRAW has in their docs.
The following code
import praw
r = praw.Reddit(user_agent="some useragent text")
r.login()
returns the following error
Traceback (most recent call last):
File "savageAxeBot.py", line 3, in <module>
r = praw.Reddit(user_agent="some useragent text")
File "/Library/Python/2.7/site-packages/praw-4.0.0b21-py2.7.egg/praw/reddit.py", line 101, in __init__
raise ClientException(required_message.format(attribute))
praw.exceptions.ClientException: Required configuration setting 'client_id' missing.
This setting can be provided in a praw.ini file, as a keyword argument to the `Reddit` class constructor, or as an environment variable.
UPDATE: I've gotten both my client ID and secret. I managed to get the above code (exactly as shown) to work on Fedora 24, not could not get it to work on either Raspbian or Mac OS X.
PRAW seems easier to use from python than the Reddit API, so I would prefer to stick with it. Also, it appears that login() is depreciated, so how can I use OAuth2 (or whatever it is called)?
Note: I installed PRAW using easy_install praw, since pip install praw wasn't working. I tried using pip on both Mac OS X 10.12 and Raspbian, and neither worked. Any ideas?
[Promoted/expanded from a comment]
As pointed out by #bboe, the PRAW docs can be located here ¹.
Specifically, you want the Getting Started ¹ page which walks you through instantiating a Reddit object in read-only or read/write mode.
¹ PRAW 4 documentation is no longer available onlne, so I've updated the links to track the latest version.
Related
I'm having a problem accessing Gmail account. Currently, I'm using this library written in python 2.7+ to log in and to read Gmail messages. To use the library, I had to enable Google 'insecure app'. Everything is working fine with this lib.
Now, I'm moving to python 3+, and I cannot use the lib anymore. Whenever I import the lib, it throws the following error:
import gmail
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python3.6/site-packages/gmail-0.0.5-py3.6.egg/gmail/__init__.py", line 16, in <module>
File "/usr/local/lib/python3.6/site-packages/gmail-0.0.5-py3.6.egg/gmail/gmail.py", line 5, in <module>
ModuleNotFoundError: No module named 'utf'
I tried to overcome this problem by looking at a replacement module for 'utf' in python 3+ but I couldn't figure out what it is. How can I fix that?
Another problem is that I tried the official python lib provided by Google. Here is the link for the tutorial. I successfully completed the quick start example, but the script opened my browser, and I had to allow the access via the browser. In fact, I just want to create a cronjob to run my script periodically on my server without an UI. Does Google allow it?
Thank you very much.
The official API for Gmail that works in python 3
and there are a lot of guides for using it, for example:
https://github.com/abhishekchhibber/Gmail-Api-through-Python
But if you feel this is too complicated (I do), instead you may want to activate access using POP3 or IMAP from the Gmail settings panel.
Then use poplib or imaplib.
Example: https://docs.python.org/3/library/poplib.html#pop3-example
This is in general easier, more portable and uses packages already found in default python installs.
Edit:
The library you were using used IMAP access, not oauth.
Also to answer your "UTF" question: every string in python 3 is UTF8 by default, if you want to decode raw data, you should use 'mystring'.decode('utf-7'), etc.
Edit 2: looks like someone already did the work: https://github.com/charlierguo/gmail/pull/48
OK, I just saw the problem in the instructions:
So, I guess your only alternative is to stick with POP3/IMAP (which your program was already using).
I downloaded the Podio API for Python and after something like ten tries I got it installed, by then I had already downloaded it 3 times from different sources, and when I got errors later (since apparantly I had downloaded and installed the Python 2-version) I was very confused and wanted to simply undo everything and install it correctly without all the crap. I tried uninstalling but it didn't work (partly I think because I don't know which method of installing it was actually successful, it just worked all of a sudden), so I just deleted everything and hoped that would at least disable it. After doing that I installed again it by typing this (relevant since I someone told me the pip-version wasn't updated, but the github-version was, and told me to type this instead. I don't understand the difference since it still says 'pip install') in the CMD:
pip install -e git+https://github.com/podio/podio-py.git#egg=podio-py
now I get this error:
from pypodio2 import OAuthClient
Traceback (most recent call last):
File "<pyshell#1>", line 1, in <module>
from pypodio2 import OAuthClient
ImportError: cannot import name 'OAuthClient'
What causes the problem? Two days of issues with this API.
OAuthClient is accessible via pypodio2.api. Change your import statement to:
from pypodio2.api import OAuthClient
client = OAuthClient('api_key', 'api_secret', 'login', 'password')
I'm developing a WPF IronPython application with VS 2015. I have to send a SOAP call and to read the answer so I'm trying to get suds to work. Since both pip and easy_install failed to install it, I downloaded the sources, unzipped them, and put them in the site-packages folder. It worked, now I can see them from VS.
When I try to use these modules however the program crashes, this is what I have done:
from suds import *
from suds.client import Client
class Utils(object):
def doStuff(addr, mail):
cl = Client(addr, verify=False)
cl.service.authenticate(email)
cl.service.otherFunctions(...)
I know that not every module works with IronPython, so my question is: have I made some error? Or is it suds that doesn't work with IronPython? If the second, do you know of alternatives?
Thank you.
I am currently attempting to use the cex.io Python API for accessing financial data. Here is a link to github with the library: https://github.com/matveyco/cex.io-api-python
I installed it on MacOS X by using "python setup.py install" in Terminal. In the link above, it says to initialize the class we should use the following:
import cexapi
api = cexapi.api(username, api_key, api_secret)
However, when I put this code in a .py file in a directory without any other files, bash responds with:
AttributeError: 'module' object has no attribute 'api'
I am pretty sure the library is correctly installed (Python has no problem importing cexapi). It is clear to me that there is something about Python objects that I don't understand or I must have incorrectly installed the module.
Just in case it helps, I ran the following in the Python interpreter:
import cexapi
cexapi.__file__
And got the following:
'/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/cexapi-0.1-py3.4.egg/cexapi/__init__.py'
This command should show where the module is stored. Any help would be greatly appreciated, as I need to use this API. Thanks.
use upper case letters:
import cexapi
api = cexapi.API(username, api_key, api_secret)
I'm using virtualenv with my application, and I've installed gdata, jira, and gspread using env/bin/pip install <lib name> in terminal under my project folder. I'm following the documentation from the Google API but it is not working?
In the documentation, in order to do error handling you need to do:
from gdata import errors
And in order to create an instance of the Drive API service (in order to later on create a file) you need to do:
from gdata.discovery import build
However the files are different, there is no "discovery" or "errors" and when I run env/bin/python run.py I get this error:
Traceback (most recent call last):
File "run.py", line 3, in <module>
from gdata import errors
ImportError: cannot import name errors
(same with discovery)
I thought that maybe they mean from apiclient import errors literally in the documentation, so I tried pip installing apiclient and replacing gdata with apiclient but it still does not work.
I downloaded the gdata.zip file and unzipped it and looked through the sample code (especially for spreadsheet since that's what I'm trying to create) and they take a very different approach than the documentation and I'm very confused. My goal is to use their API to just create a spreadsheet from the code, but I do not plan on using their API to edit the spreadsheet itself, I plan on using gspread (Github).
I've done a lot of research and I've been directed to a lot of different places and I might have perhaps mixed up the code? Does anyone know what I did wrong/have a fix? A huge thanks in advance.
This kind of import error is usually caused by the user installing another module of the same name. Do you by any chance have a gdata.py somehwere on your Python path?
You can verify whether this is causing the issue by:
import gdata
print gdata.__file__
This tells you where the interpreter is loading the code from.