Django_ses with boto versions above 2.1 - django

Im trying to send email using the send_mail call from within a django application previously I had used django_ses, but I have hit on an issue.
I know the django_ses library (https://pypi.python.org/pypi/django-ses) isn't maintained actively, though it claims to still be widely in use. I've recently upgraded the boto version on the machine to the latest (2.31) and im getting a certificate error when trying to send an email (Stack trace included below). I've confirmed that returning boto to version 2.1 stops the error, so im guessing the two are incompatable. Has anyone managed to patch around the issue?
thanks
Steve
>>> send_mail('Test subject', 'This is the body', 'donotreply#example.com',['someone#example.com'], fail_silently=False)
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "/usr/local/lib/python2.7/dist-packages/django/core/mail/__init__.py", line 61, in send_mail
File "/usr/local/lib/python2.7/dist-packages/django/core/mail/message.py", line 248, in send
File "/usr/local/lib/python2.7/dist-packages/django_ses-0.6.0-py2.7.egg/django_ses/__init__.py", line 122, in send_messages
rate_limit = self.get_rate_limit()
File "/usr/local/lib/python2.7/dist-packages/django_ses-0.6.0-py2.7.egg/django_ses/__init__.py", line 196, in get_rate_limit
quota_dict = self.connection.get_send_quota()
File "/usr/local/lib/python2.7/dist-packages/boto/ses/connection.py", line 339, in get_send_quota
File "/usr/local/lib/python2.7/dist-packages/boto/ses/connection.py", line 101, in _make_request
File "/usr/local/lib/python2.7/dist-packages/boto/connection.py", line 932, in make_request
File "/usr/local/lib/python2.7/dist-packages/boto/connection.py", line 894, in _mexe
SSLError: [Errno 185090050] _ssl.c:340: error:0B084002:x509 certificate routines:X509_load_cert_crl_file:system lib

Turns out the problem wasn't a version incomparability, but where my server was located. From the experimenting I've done, django_ses doesn't play well when not on an EC2 machine. I switched to using the smtp library which drops in just as easily and im away.
https://github.com/bancek/django-smtp-ssl

Related

PyMongo 3 and ServerSelectionTimeoutError while getting data from Mongodb

This seems like an old solved problem here and here and here but Still I am getting this error.I create my db on Docker.And It worked only one time.Before this, I re-created db, did "connect =false",added wait, downgraded pymongo, did previous solutions etc. I stuck.
Python 3.8.0, Pymongo 3.9.0
from pymongo import MongoClient
import pprint
client = MongoClient('mongodb://192.168.1.100:27017/',
username='admin',
password='psw',
authSource='myappdb',
authMechanism='SCRAM-SHA-1',
connect=False)
db = client['myappdb']
serverStatusResult=db.command("serverStatus")
pprint(serverStatusResult)
and I am getting ServerSelectionTimeoutError
Traceback (most recent call last):
File "C:\Users\ME\eclipse2019-workspace\exdjango\exdjango__init__.py",
line 12, in
serverStatusResult=db.command("serverStatus")
File "C:\Users\ME\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pymongo\database.py",
line 610, in command
with self.client._socket_for_reads(
File "C:\Users\ME\AppData\Local\Programs\Python\Python38-32\lib\contextlib.py",
line 113, in __enter
return next(self.gen)
File "C:\Users\ME\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pymongo\mongo_client.py",
line 1099, in _socket_for_reads
server = topology.select_server(read_preference)
File "C:\Users\ME\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pymongo\topology.py",
line 222, in select_server
return random.choice(self.select_servers(selector,
File "C:\Users\ME\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pymongo\topology.py",
line 182, in select_servers
server_descriptions = self._select_servers_loop(
File "C:\Users\ME\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pymongo\topology.py",
line 198, in _select_servers_loop
raise ServerSelectionTimeoutError(
pymongo.errors.ServerSelectionTimeoutError: 192.168.1.100:27017: timed out
Your connection looks a little misconfigured. Firstly you have half connection string, half parameter format. I'd suggest you stick with one or the other.
Your auth database is usually seperate to your actual databases (and it's usually called admin). Check this is correct.
There's no particular need to specify the authMechanism assuming you are using MongoDB 3.0 or later.
The connect=False is likely a red herring.
So I would try one of either:
client = MongoClient('mongodb://admin:psw#192.168.1.100:27017/myappdb?authSource=admin')
or
client = MongoClient(host='192.168.1.100',
port=27017,
username='admin',
password='psw',
authSource='admin')

Using tools.run_flow() raises SSLHandshake "certificate verify" error in Google Sheets API tutorial

I'm am pretty much following the Google Sheets getting started (in Python) to a tee. I've gotten the program to work on my Mac laptop, but it is failing as I am trying to run it on Windows. So far, I've checked that we do not have the firewall enabled on the machine.
Below is the error that appears after clicking through the authentication prompts that pop up in the browser.
Traceback (most recent call last):
File "Authenticate.py", line 47, in <module>
main()
File "Authenticate.py", line 43, in main
tools.run_flow(flow, store)
File "C:\johnsnow\packages\test\lib\site-packages\oauth2client\_helpers.py", line 133, in positional_wrapper
return wrapped(*args, **kwargs)
File "C:\johnsnow\packages\test\lib\site-packages\oauth2client\tools.py", line 243, in run_flow
credential = flow.step2_exchange(code, http=http)
File "C:\johnsnow\packages\test\lib\site-packages\oauth2client\_helpers.py", line 133, in positional_wrapper
return wrapped(*args, **kwargs)
File "C:\johnsnow\packages\test\lib\site-packages\oauth2client\client.py", line 2054, in step2_exchange
http, self.token_uri, method='POST', body=body, headers=headers)
File "C:\johnsnow\packages\test\lib\site-packages\oauth2client\transport.py", line 282, in request
connection_type=connection_type)
File "C:\johnsnow\packages\test\lib\site-packages\httplib2\__init__.py", line 1570, in request
(response, content) = self._request(conn, authority, uri, request_uri, method, body, headers, redirections, cachekey)
File "C:\johnsnow\packages\test\lib\site-packages\httplib2\__init__.py", line 1317, in _request
(response, content) = self._conn_request(conn, request_uri, method, body, headers)
File "C:\johnsnow\packages\test\lib\site-packages\httplib2\__init__.py", line 1252, in _conn_request
conn.connect()
File "C:\johnsnow\packages\test\lib\site-packages\httplib2\__init__.py", line 1044, in connect
raise SSLHandshakeError(e)
httplib2.SSLHandshakeError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:661)
I'm not exactly sure how it happened as I was working in a virtualenv, but there was a dependency issue in the version of httplib2 and oauth2. After an uninstall and then reinstall, there was an error that the two libraries were incompatible.
Doing pip freeze showed I had httplib2==0.8 but oauth2client required httplib2=>0.9.
This was resolved by doing pip install --upgrade httplib2.

Trying to setup a Ghost blog with Buster

I'm trying to set up a static Ghost blog with Github hosting using the Buster Static generator. I've tried various instructions including:
https://stefanscherer.github.io/setup-ghost-for-github-pages/
http://blog.sunnyg.io/2015/09/24/ghost-with-github/
But when I get to the "buster generate" command I get the following output in terminal.
It is running fine locally.
Can anyone point me in the right direction?
buster generate
--2016-03-07 23:53:11-- http://localhost:2368/
Resolving localhost... ::1, 127.0.0.1
Connecting to localhost|::1|:2368... failed: Connection refused.
Connecting to localhost|127.0.0.1|:2368... connected.
HTTP request sent, awaiting response... 200 OK
Length: 4508 (4.4K) [text/html]
Saving to: '/Users/philip/Development/Node/ghost-0.7.8/static/index.html'
fixing links in /Users/philip/Development/Node/ghost-0.7.8/static/index.html
Traceback (most recent call last):
File "/usr/local/bin/buster", line 9, in <module>
load_entry_point('buster==0.1.3', 'console_scripts', 'buster')()
File "/usr/local/Cellar/python/2.7.8_2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/buster/buster.py", line 90, in main
newtext = fixLinks(filetext, parser)
File "/usr/local/Cellar/python/2.7.8_2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/buster/buster.py", line 64, in fixLinks
d = PyQuery(bytes(bytearray(text, encoding='utf-8')), parser=parser)
File "/usr/local/Cellar/python/2.7.8_2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pyquery/pyquery.py", line 226, in __init__
elements = fromstring(context, self.parser)
File "/usr/local/Cellar/python/2.7.8_2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pyquery/pyquery.py", line 90, in fromstring
result = custom_parser(context)
File "/usr/local/Cellar/python/2.7.8_2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/lxml/html/__init__.py", line 867, in fromstring
doc = document_fromstring(html, parser=parser, base_url=base_url, **kw)
File "/usr/local/Cellar/python/2.7.8_2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/lxml/html/__init__.py", line 752, in document_fromstring
value = etree.fromstring(html, parser, **kw)
File "src/lxml/lxml.etree.pyx", line 3213, in lxml.etree.fromstring (src/lxml/lxml.etree.c:82934)
File "src/lxml/parser.pxi", line 1819, in lxml.etree._parseMemoryDocument (src/lxml/lxml.etree.c:124533)
File "src/lxml/parser.pxi", line 1707, in lxml.etree._parseDoc (src/lxml/lxml.etree.c:123074)
File "src/lxml/parser.pxi", line 1079, in lxml.etree._BaseParser._parseDoc (src/lxml/lxml.etree.c:117114)
File "src/lxml/parser.pxi", line 573, in lxml.etree._ParserContext._handleParseResultDoc (src/lxml/lxml.etree.c:110510)
File "src/lxml/parser.pxi", line 683, in lxml.etree._handleParseResult (src/lxml/lxml.etree.c:112276)
File "src/lxml/parser.pxi", line 624, in lxml.etree._raiseParseError (src/lxml/lxml.etree.c:111367)lxml.etree.XMLSyntaxError: None
As stated in the comment, I did get in working however instead of just doing the 'Quick Install' recommended by many, I went the route of the 'Developer Install' guide here https://github.com/TryGhost/Ghost using the Stable branch.
After you run through that (with your local server running), in another terminal, run
$ buster setup
<Enter git repo>
$ buster generate --domain=localhost:2368
$ buster deploy (or as most sane people prefer, just git push)
Full instructions here: http://phil-a.github.io/getting-ghost-running-on-github-with-buster

Python Beatbox to Salesforce Error Connecting to Salesforce

I just had my computer re-imaged and have Python 2.7.9 (64-bit) installed on my machine. Using PIP I have beatbox 32.1 installed.
When I make the call to connect to Salesforce:
sf_client.login(sf_username, sf_password)
logging.info('Connected successfully')
I receive an error message. I have tried just the normal login credentials which has always worked and have attempted to connect with my token in the password too.
Has anyone run into this error with Python Beatbox and do you know what debugging options I could try to get to the bottom of this?
Traceback (most recent call last):
File "C:\myCode\salesforceload_beatbox.py", line 126, in <module>
sf_client.login(sf_username, sf_password)
File "C:\Python27\lib\site-packages\beatbox\python_client.py", line 76, in login
res = BaseClient.login(self, username, passwd)
File "C:\Python27\lib\site-packages\beatbox\_beatbox.py", line 62, in login
lr = LoginRequest(self.serverUrl, username, password).post()
File "C:\Python27\lib\site-packages\beatbox\_beatbox.py", line 330, in post
raise RuntimeError('No response from Salesforce')
RuntimeError: No response from Salesforce
After digging deeper into this (and debugging the HTTP connection with requests package), I'm failing at this level
Traceback (most recent call last):
File "C:\myCode\SFDC\test_beatbox_call2.py", line 34, in <module>
requests.get(sf_client.login(sf_username, sf_password))
File "C:\Python27\lib\site-packages\beatbox\python_client.py", line 76, in login
res = BaseClient.login(self, username, passwd)
File "C:\Python27\lib\site-packages\beatbox\_beatbox.py", line 78, in login
lr = LoginRequest(self.serverUrl, username, password).post()
File "C:\Python27\lib\site-packages\beatbox\_beatbox.py", line 344, in post
conn.request("POST", path, self.makeEnvelope(), headers)
File "C:\Python27\lib\httplib.py", line 1001, in request
self._send_request(method, url, body, headers)
File "C:\Python27\lib\httplib.py", line 1035, in _send_request
self.endheaders(body)
File "C:\Python27\lib\httplib.py", line 997, in endheaders
self._send_output(message_body)
File "C:\Python27\lib\httplib.py", line 850, in _send_output
self.send(msg)
File "C:\Python27\lib\httplib.py", line 812, in send
self.connect()
File "C:\Python27\lib\httplib.py", line 1216, in connect
server_hostname=server_hostname)
File "C:\Python27\lib\ssl.py", line 350, in wrap_socket
_context=self)
File "C:\Python27\lib\ssl.py", line 566, in __init__
self.do_handshake()
File "C:\Python27\lib\ssl.py", line 788, in do_handshake
self._sslobj.do_handshake()
ssl.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:581)
After searching and googling profusely about TLS connections, etc, I noticed this weekend that my cmd.exe window (which I run the PIP commands from) was launching under C:\Windows\System32> and all of my vms were launching within my personal user directory.
So I searched for my roaming cmd.exe and when I opened that, it was to my personal user directory.
After doing an uninstall and install of beatbox using PIP in the new cmd.exe, all of my Salesforce calls via Beatbox work like they used to.
Now I can't fully explain why this is the case, but something tells me that the certs for this admin location are probably mismatched to my personal certificates. I'm up and running again.

why youtube_upload is giving xml.etree.ElementTree.ParseError in python 2.7 on linux

I am new to python and while searching i found that i can upload a video to youtube in command line in linux and i am using centos 5.7
i first installed python 2.7 and face many problems in doing it but i search it on google and find answers
one main problem had faced and solved the httpsconnection and after installing the open ssl and openssl-devel it is ok
i am using this command in order to Upload the video:
>python youtube_upload.py --email="test.for.utube#gmail.com" --password="****" --title="test" --category="test" test.mp4
and getting this result:
Login to Youtube API: email='test.for.utube#gmail.com', password='********' Traceback (most recent call last):
File "youtube_upload.py", line 449, in <module>
sys.exit(catch_exceptions(EXIT_CODES, main_upload, sys.argv[1:]))
File "youtube_upload.py", line 105, in catch_exceptions
fun(*args, **kwargs)
File "youtube_upload.py", line 381, in main_upload
captcha_response=options.captcha_response)
File "youtube_upload.py", line 183, in login
self.categories = self.get_categories()
File "youtube_upload.py", line 255, in get_categories
xml = ElementTree.XML(xmldata)
File "/usr/local/lib/python2.7/xml/etree/ElementTree.py", line 1301, in XML
parser.feed(text)
File "/usr/local/lib/python2.7/xml/etree/ElementTree.py", line 1643, in feed
self._raiseerror(v)
File "/usr/local/lib/python2.7/xml/etree/ElementTree.py", line 1507, in _raiseerror
raise err
xml.etree.ElementTree.ParseError: syntax error: line 1, column 49
and didn't find any solution on google.
so I hope that anyone can help me to successfully complete the youtube upload through the command line.
Thanks at all. and if I can have a fast reply about the time expected to have a solution so i know how much should i wait
I have no idea what youtube_upload.py is, but if you're looking for a "canonical" Python command line script that supports YouTube uploads (and supports OAuth 2 for authorization), try http://code.google.com/p/googlecl/