python - importing modules on shared server
i have a script named gmailCleaner.py, on my pc it runs great and ajusts my gmail (using imap) just the way i want.
so i wanted to make this script availabl to everybody on my website (shared hosting, python enabled) the script runs but fails to connect to gmail (using same settings as in my pc, only diffrence is that on pc i use raw_input and on the server i use fata from html form)
i assumed it was because they lack the imaplib file i was using - so i uploaded it to the server (same folder as the script) it didnt work.
new: getting this error: 'module' object has no attribute 'IMAP4_SSL'
any kind of help will be good
the code:
#!/usr/bin/python
import imaplib
import os
import cgi
print 'Content-type: text/html\n\n'
try:
M=imaplib.IMAP4_SSL('imap.gmail.com', 993)
except:
print 'cannot connect to gmail<br />'
and it fails :S it prints the 'cannot connect to gmail' means it runs.
edit for comment, not yet the most user friendly code ever, just wanted it to work first (deleting all emails from pes开发者_运维知识库ific sender):
try:
USER = form.getvalue('username')
PASS = form.getvalue('password')
SENDER = form.getvalue('from')
print USER
except:
print 'cannot get form info<br />'
try:
M=imaplib.IMAP4_SSL('imap.gmail.com', 993)
M.login(USER +'@gmail.com',PASS)
status, count = M.select('Inbox')
except Exception as e: print e
try:
SENDER = '\"' + SENDER + '\"'
data = M.search(None, 'FROM', SENDER)
a = str(data[1])
a = a.split()
b = ''
i = 0
while i < len(a[-1]) - 2:
b = b + a[-1][i]
i += 1
a[-1] = b
b = ''
i = 2
while i < len(a[0]):
b = b + a[0][i]
i += 1
a[0] = b
except:
print 'cannot get ids<br />'
try:
print 'deleting!<br />'
i = 0
while i < len(a):
M.store(a[i], '+FLAGS', '\\Deleted')
i += 1
except:
print 'cannot delete<br />'
If your shared server supports pip install and virtualenv, try this
virtualenv env --no-site-packages
pip install python<version>
pip install otherpythonpackages
This should solve your problem.
精彩评论