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).
Related
Hello there,
i am writing a code for auto discovery of IP within the network and then
data transfer using the socket programming in python. I have read the RSA
and want to implement in the code. i go through to the link where i got
the code implementation and the whole code for server and client.
Here is the link where the code is:
<https://riptutorial.com/python/example/27170/client-side-implementation>
<https://riptutorial.com/python/example/27169/server-side-implementation>
There are two links and the setup for PyCrypto is.
*PyCrypto (Download Link: https://pypi.python.org/pypi/pycrypto )
*PyCryptoPlus (Download Link: https://github.com/doegox/python-cryptoplus )
i tried it on raspberry pi and install all the essential modules which i wrote above, and run it using the command line as follows:
python3 server.py
but it gives me some module related errors.
Crypto.Cipher.IDEA isn't available. You're probably using the Debian
pycrypto version. Install the original pycrypto for IDEA.
Traceback (most recent call last):
File "serverRsa.py", line 10, in <module>
from CryptoPlus.Cipher import IDEA
File "/home/pi/.local/lib/python3.5/site-
packages/CryptoPlus/Cipher/IDEA.py", line 4, in <module>
import Crypto.Cipher.IDEA
ImportError: No module named 'Crypto.Cipher.IDEA'
i tried it using the pip install PyCrypto and using the same with pip3.
and then run the same code but same error occurred.
Actually problem statement is to auto discover of all the nearby ip's
using the python programming , where i run the code on Raspberry Pi and
make it as a hotspot and other Pi boards act as client. Now when the
server found the client or discover them then it register them using some
key or encryption method.
i just need or code that passes some message to client using RSA but it seems the code have error.
Anyone please fix this issue.
Crypto.Cipher doesn't have any attribute named: IDEA.
import Crypto.Cipher.IDEA #won't work -_-
Maybe what you are looking for is CryptoPlus:
import CryptoPlus.Cipher.IDEA
If you really need an IDEA cipher in Python 2, and it's OK for you that it's slow (much slower than if it was implemented in C), there is one here: https://pastebin.com/hTn5K3Tx . Use it like this:
cb = IDEA('2bd6459f82c5b300952c49104881ff48'.decode('hex'))
plaintext, ciphertext = 'f129a6601ef62a47'.decode('hex'), 'ea024714ad5c4d84'.decode('hex')
assert cb.encrypt(plaintext) == ciphertext
assert cb.decrypt(ciphertext) == plaintext
Please note that the last patent on IDEA expired in 2012, and now IDEA is free to use for the public.
Standard Crypto Ciphers installed with pip install pycrypto now is version 2.6.1 and because of license restrictions it doesn't include IDEA (Crypto.Cipher.IDEA)
If you want to install Crypto.Cipher.IDEA you must find pycrypto-2.0.1 (freely available for download) which was last used to embedded this crypto cipher see pts comment above. Then follow the standard procedure to install the package pycrypto
python setup.py install
Problem appear if want to install IDEA for pyton3.
I am currently experimenting with a python API for Snapchat that was derived from the PHP API. I am running my program from a Windows 10 laptop from Asus. It seems that I am getting a consistent error that is telling me I need to update my software OS or update Snapchat, which is weird because I have the latest version of windows and there is no Snapchat on windows.
After researching the problem, it seemed it was a common message given on jailbroken phones in an attempt to counter third party developers. It seems that I am the only one having this problem, as I looked around the internet and no one else seemed to complain. Could Someone please help me get around this issue and explain why this is occurring? Thank you in advance
>>> import pysnap
>>> snapchat = pysnap.Snapchat()
>>> snapchat.login('username', 'password')
Traceback (most recent call last):
File "<pyshell#13>", line 1, in <module>
snapchat().login('username', 'password')
File "build\bdist.win32\egg\pysnap\__init__.py", line 113, in login
raise Exception(result.get('message', 'unknown error'))
Exception: You're using a version of Snapchat or operating system that's no longer supported. Please upgrade your device's operating system and update to the newest app version to use Snapchat. Thanks!
I don't know that I have a solution, but it looks like several similar libraries have dealt with problems as well:
SnapchatBot
https://github.com/agermanidis/SnapchatBot/issues/52
Snapchat PHP SDK
https://github.com/liamcottle/Snapchat-SDK-PHP/issues/38
It does look as though the PHP SDK solved the problem, though it doesn't look like the solution is explicitly stated there.
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.
I am working on a "chat-like" server using Twisted in Python. However I am having issues. On the main admin account of my Mac, Twisted works fine. But when I go onto a separate admin account, I get thrown...
Traceback (most recent call last):
File "/Users/Alec/Desktop/server.py", line 1, in <module>
from twisted.internet.protocol import Protocol, Factory
ImportError: No module named twisted.internet.protocol
It works fine on the other account, but this new admin account doesn't work. I am working hard to get my project going, but this has me at a halt.
Thanks!
I can only guess at what's wrong with your setup, since you haven't provided much information. However, the cause must be something to do with the way you're invoking python, since the default python on OS X has Twisted installed (as you may have noticed).
Does your administrative user have a self-compiled Python?
Is your administrative user using virtualenv, or any other environment-management tool that would remove site-packages?
Did your administrative user install Python from python.org? (This is not completely compatible with the built-in system Python and will have different packages available.)
If type -p python in a shell doesn't print /usr/bin/python, then one of these is likely the case, but fixing it (in other words, un-doing whatever has been done) depends on which of these options has altered your default Python.
You might want to check if sys.path (the module search path) is the same for both users.
>>> import sys
>>> sys.path
There may be a user specific PYTHONPATH environment variable which alters the behavior for one of the two users, although I'm not sure it could actually break the import.
I'm trying to write a python script for BusyBox on ESXi with mail functionality. It runs Python 2.5 with some libraries missing (i.e. the smtplib). I downloaded Python2.5 sources and copied the lib-folder to ESXi. Now I am trying to import the smtplib via "import lib.smtplib" but Python says:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/pysexi/lib/smtplib.py", line 46, in <module>
import email.Utils
File "/pysexi/lib/email/__init__.py", line 115, in <module>
setattr(sys.modules['email'], _name, importer)
KeyError: 'email'
I'm stuck. So every help and every thought is appreciated!
Trying to install generic applications on an appliance or custom OS is always fun.
Just a guess, but it may be that the email lib is a compiled C module - i.e. not pure python.
I would try use libraries that are as completely python with no compiled code - I don't know if there are pure python versions of the libraries.
The option is to try to track down what OS version that ESXi is based on and then use the matching python version from that OS.
I don't know anything about BusyBox or ESXi - therefore this may be more of a suggestion than an answer, but you might consider using a email service that supports an HTTP or RESTful API - such as MailGun. They have a free plan for up to 200 emails a day, so it might not cost you anything.
Again, this way be more of a suggestion or a plan "B" (if no one can help you with this specific problem)