Unable to create imap object in python2.7 - python-2.7

I get an error whenever I try to create imap object in my personal domain in python2. It however succeeds with gmail
import imaplib
imap = imaplib.IMAP4_SSL("imap.gmail.com") # Success
imap2 = imaplib.IMAP4_SSL("mail.mosesotieno.com") # Failure
I get an error
File "C:\Python27\Lib\imaplib.py", line 1148, in __init__
IMAP4.__init__(self, host, port)
File "C:\Python27\Lib\imaplib.py", line 163, in __init__
self.open(host, port)
File "C:\Python27\Lib\imaplib.py", line 1160, in open
self.sslobj = ssl.wrap_socket(self.sock, self.keyfile, self.certfile)
File "C:\Python27\Lib\ssl.py", line 387, in wrap_socket
ciphers=ciphers)
File "C:\Python27\Lib\ssl.py", line 143, in __init__
self.do_handshake()
File "C:\Python27\Lib\ssl.py", line 305, in do_handshake
self._sslobj.do_handshake()
ssl.SSLError: [Errno 8] _ssl.c:504: EOF occurred in violation of protocol

Related

`capture_tpu_profile` not able to access the TPU

I have the following TPU:
$ gcloud compute tpus list
NAME ZONE ACCELERATOR_TYPE NETWORK_ENDPOINTS NETWORK RANGE STATUS
daniels-tpu us-central1-a v3-8 10.240.1.10:8470 default 10.240.1.8/29 READY
But it is not accessible via capture_tpu_profile:
$ capture_tpu_profile --tpu=daniels-tpu
TensorFlow version 1.15.2 detected
WARNING:tensorflow:
The TensorFlow contrib module will not be included in TensorFlow 2.0.
For more information, please see:
* https://github.com/tensorflow/community/blob/master/rfcs/20180907-contrib-sunset.md
* https://github.com/tensorflow/addons
* https://github.com/tensorflow/io (for I/O related ops)
If you depend on functionality not listed there, please file an issue.
W0131 10:15:16.553251 4571966912 lazy_loader.py:50]
The TensorFlow contrib module will not be included in TensorFlow 2.0.
For more information, please see:
* https://github.com/tensorflow/community/blob/master/rfcs/20180907-contrib-sunset.md
* https://github.com/tensorflow/addons
* https://github.com/tensorflow/io (for I/O related ops)
If you depend on functionality not listed there, please file an issue.
Traceback (most recent call last):
File "/usr/local/Cellar/python/3.7.6_1/Frameworks/Python.framework/Versions/3.7/lib/python3.7/urllib/request.py", line 1319, in do_open
encode_chunked=req.has_header('Transfer-encoding'))
File "/usr/local/Cellar/python/3.7.6_1/Frameworks/Python.framework/Versions/3.7/lib/python3.7/http/client.py", line 1252, in request
self._send_request(method, url, body, headers, encode_chunked)
File "/usr/local/Cellar/python/3.7.6_1/Frameworks/Python.framework/Versions/3.7/lib/python3.7/http/client.py", line 1298, in _send_request
self.endheaders(body, encode_chunked=encode_chunked)
File "/usr/local/Cellar/python/3.7.6_1/Frameworks/Python.framework/Versions/3.7/lib/python3.7/http/client.py", line 1247, in endheaders
self._send_output(message_body, encode_chunked=encode_chunked)
File "/usr/local/Cellar/python/3.7.6_1/Frameworks/Python.framework/Versions/3.7/lib/python3.7/http/client.py", line 1026, in _send_output
self.send(msg)
File "/usr/local/Cellar/python/3.7.6_1/Frameworks/Python.framework/Versions/3.7/lib/python3.7/http/client.py", line 966, in send
self.connect()
File "/usr/local/Cellar/python/3.7.6_1/Frameworks/Python.framework/Versions/3.7/lib/python3.7/http/client.py", line 938, in connect
(self.host,self.port), self.timeout, self.source_address)
File "/usr/local/Cellar/python/3.7.6_1/Frameworks/Python.framework/Versions/3.7/lib/python3.7/socket.py", line 707, in create_connection
for res in getaddrinfo(host, port, 0, SOCK_STREAM):
File "/usr/local/Cellar/python/3.7.6_1/Frameworks/Python.framework/Versions/3.7/lib/python3.7/socket.py", line 752, in getaddrinfo
for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
socket.gaierror: [Errno 8] nodename nor servname provided, or not known
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/local/bin/capture_tpu_profile", line 8, in <module>
sys.exit(run_main())
File "/usr/local/lib/python3.7/site-packages/cloud_tpu_profiler/main.py", line 85, in run_main
tf.compat.v1.app.run(main)
File "/usr/local/lib/python3.7/site-packages/tensorflow_core/python/platform/app.py", line 40, in run
_run(main=main, argv=argv, flags_parser=_parse_flags_tolerate_undef)
File "/usr/local/lib/python3.7/site-packages/absl/app.py", line 299, in run
_run_main(main, args)
File "/usr/local/lib/python3.7/site-packages/absl/app.py", line 250, in _run_main
sys.exit(main(argv))
File "/usr/local/lib/python3.7/site-packages/cloud_tpu_profiler/main.py", line 105, in main
[FLAGS.tpu], zone=FLAGS.tpu_zone, project=FLAGS.gcp_project))
File "/usr/local/lib/python3.7/site-packages/tensorflow_core/python/distribute/cluster_resolver/tpu_cluster_resolver.py", line 330, in __init__
self._request_compute_metadata('project/project-id'))
File "/usr/local/lib/python3.7/site-packages/tensorflow_core/python/distribute/cluster_resolver/tpu_cluster_resolver.py", line 124, in _request_compute_metadata
resp = urlopen(req)
File "/usr/local/Cellar/python/3.7.6_1/Frameworks/Python.framework/Versions/3.7/lib/python3.7/urllib/request.py", line 222, in urlopen
return opener.open(url, data, timeout)
File "/usr/local/Cellar/python/3.7.6_1/Frameworks/Python.framework/Versions/3.7/lib/python3.7/urllib/request.py", line 525, in open
response = self._open(req, data)
File "/usr/local/Cellar/python/3.7.6_1/Frameworks/Python.framework/Versions/3.7/lib/python3.7/urllib/request.py", line 543, in _open
'_open', req)
File "/usr/local/Cellar/python/3.7.6_1/Frameworks/Python.framework/Versions/3.7/lib/python3.7/urllib/request.py", line 503, in _call_chain
result = func(*args)
File "/usr/local/Cellar/python/3.7.6_1/Frameworks/Python.framework/Versions/3.7/lib/python3.7/urllib/request.py", line 1347, in http_open
return self.do_open(http.client.HTTPConnection, req)
File "/usr/local/Cellar/python/3.7.6_1/Frameworks/Python.framework/Versions/3.7/lib/python3.7/urllib/request.py", line 1321, in do_open
raise URLError(err)
urllib.error.URLError: <urlopen error [Errno 8] nodename nor servname provided, or not known>
The error didn't go away even after using --tpu_zone=us-central1-a flag.
When you use capture_tpu_profile to capture a profile, a .tracetable file is saved to your Google Cloud Storage bucket, if this location is not provided, then it will go nowhere.
Can you try adding the path of you bucket with the following command:
capture_tpu_profile --tpu=tpu-name --logdir=${MODEL_DIR}
--logdir=${MODEL_DIR} - This is a Cloud Storage location where your model and checkpoints are stored.
All details mentioned in this documentation

"[Errno 8] nodename nor servname provided, or not known" when using django-ses

I'm trying to plug django-ses into my project. I've followed instructions laid out in this tutorial:
https://kholinlabs.com/the-easiest-way-to-send-emails-with-django
Although I believe I've followed these closely, when sending a test email I receive this error:
File "/usr/local/Cellar/python/3.6.5_1/Frameworks/Python.framework/Versions/3.6/lib/python3.6/socket.py", line 745, in getaddrinfo
for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
socket.gaierror: [Errno 8] nodename nor servname provided, or not known
I've successfully registered with SES and validated the email I'm using to send.
The error occurs either when sending from the python console or from the app.
These are my relevant settings:
EMAIL_BACKEND = 'django_ses.SESBackend'
AWS_SES_REGION_NAME = 'eu-west-2'
AWS_SES_REGION_ENDPOINT = 'email.eu-west-2.amazonaws.com'
AWS_SES_ACCESS_KEY_ID = '{secret key}'
AWS_SES_SECRET_ACCESS_KEY = '{secret access key}'
AWS_SES_AUTO_THROTTLE = 0.5
How can I fix this?
Command used to send emaik
from django.core.mail import send_mail
send_mail(
'Subject here',
'Here is the message.',
'from#example.com',
['to#example.com'],
fail_silently=False,
)
Full stack trace
Traceback (most recent call last):
File "/Applications/PyCharm.app/Contents/helpers/pydev/pydevd.py", line 1758, in <module>
main()
File "/Applications/PyCharm.app/Contents/helpers/pydev/pydevd.py", line 1752, in main
globals = debugger.run(setup['file'], None, None, is_module)
File "/Applications/PyCharm.app/Contents/helpers/pydev/pydevd.py", line 1147, in run
pydev_imports.execfile(file, globals, locals) # execute the script
File "/Applications/PyCharm.app/Contents/helpers/pydev/_pydev_imps/_pydev_execfile.py", line 18, in execfile
exec(compile(contents+"\n", file, 'exec'), glob, loc)
File "/Users/user/Desktop/app/manage.py", line 15, in <module>
execute_from_command_line(sys.argv)
File "/Users/user/python-venvs/app/lib/python3.6/site-packages/django/core/management/__init__.py", line 381, in execute_from_command_line
utility.execute()
File "/Users/user/python-venvs/app/lib/python3.6/site-packages/django/core/management/__init__.py", line 375, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/Users/user/python-venvs/app/lib/python3.6/site-packages/django/core/management/base.py", line 323, in run_from_argv
self.execute(*args, **cmd_options)
File "/Users/user/python-venvs/app/lib/python3.6/site-packages/django/core/management/base.py", line 364, in execute
output = self.handle(*args, **options)
File "/Users/user/Desktop/app/letters/management/commands/test_email.py", line 19, in handle
fail_silently=False,
File "/Users/user/python-venvs/app/lib/python3.6/site-packages/django/core/mail/__init__.py", line 60, in send_mail
return mail.send()
File "/Users/user/python-venvs/app/lib/python3.6/site-packages/django/core/mail/message.py", line 291, in send
return self.get_connection(fail_silently).send_messages([self])
File "/Users/user/python-venvs/app/lib/python3.6/site-packages/django_ses/__init__.py", line 157, in send_messages
rate_limit = self.get_rate_limit()
File "/Users/user/python-venvs/app/lib/python3.6/site-packages/django_ses/__init__.py", line 247, in get_rate_limit
quota_dict = self.connection.get_send_quota()
File "/Users/user/python-venvs/app/lib/python3.6/site-packages/boto/ses/connection.py", line 341, in get_send_quota
return self._make_request('GetSendQuota')
File "/Users/user/python-venvs/app/lib/python3.6/site-packages/boto/ses/connection.py", line 102, in _make_request
data=urllib.parse.urlencode(params)
File "/Users/user/python-venvs/app/lib/python3.6/site-packages/boto/connection.py", line 1071, in make_request
retry_handler=retry_handler)
File "/Users/user/python-venvs/app/lib/python3.6/site-packages/boto/connection.py", line 1030, in _mexe
raise ex
File "/Users/user/python-venvs/app/lib/python3.6/site-packages/boto/connection.py", line 943, in _mexe
request.body, request.headers)
File "/usr/local/Cellar/python/3.6.5_1/Frameworks/Python.framework/Versions/3.6/lib/python3.6/http/client.py", line 1239, in request
self._send_request(method, url, body, headers, encode_chunked)
File "/usr/local/Cellar/python/3.6.5_1/Frameworks/Python.framework/Versions/3.6/lib/python3.6/http/client.py", line 1285, in _send_request
self.endheaders(body, encode_chunked=encode_chunked)
File "/usr/local/Cellar/python/3.6.5_1/Frameworks/Python.framework/Versions/3.6/lib/python3.6/http/client.py", line 1234, in endheaders
self._send_output(message_body, encode_chunked=encode_chunked)
File "/usr/local/Cellar/python/3.6.5_1/Frameworks/Python.framework/Versions/3.6/lib/python3.6/http/client.py", line 1026, in _send_output
self.send(msg)
File "/usr/local/Cellar/python/3.6.5_1/Frameworks/Python.framework/Versions/3.6/lib/python3.6/http/client.py", line 964, in send
self.connect()
File "/Users/user/python-venvs/app/lib/python3.6/site-packages/boto/https_connection.py", line 119, in connect
sock = socket.create_connection((self.host, self.port), self.timeout)
File "/usr/local/Cellar/python/3.6.5_1/Frameworks/Python.framework/Versions/3.6/lib/python3.6/socket.py", line 704, in create_connection
for res in getaddrinfo(host, port, 0, SOCK_STREAM):
File "/usr/local/Cellar/python/3.6.5_1/Frameworks/Python.framework/Versions/3.6/lib/python3.6/socket.py", line 745, in getaddrinfo
for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
socket.gaierror: [Errno 8] nodename nor servname provided, or not known
Process finished with exit code 1
socket.gaierror: [Errno 8] nodename nor servname provided, or not known
This caused because your application cannot reach your mail server, there are some reason which might cause this issue, not properly configure SES, wrong email server endpoint, wrong credentials.
So you can follow below steps to figure it out.
Configure your SES (verify your emails/domains) and get SMTP credentials. So at this step you've got:
Server Name: email-smtp.<region>.amazonaws.com (e.g: email-smtp.us-west-2.amazonaws.com)
Authentication: Your SMTP credentials.
Verify your SES configuration by send testing email, follow these steps to verify that your SES was properly configure.
Set SES up for your application. E.g:
AWS_SES_REGION_NAME = 'us-west-2'
AWS_SES_REGION_ENDPOINT = 'email-smtp.us-west-2.amazonaws.com'
AWS_SES_ACCESS_KEY_ID = '{secret key}'
AWS_SES_SECRET_ACCESS_KEY = '{secret access key}'
Test sending email on your application
There are something you might want to double check when you've followed steps above but still unable to send email:
Your AWS_SES_ACCESS_KEY_ID and AWS_SES_SECRET_ACCESS_KEY should be generated from IAM user which you use to perform step 2.
AWS_SES_REGION_ENDPOINT is one of these 3 available endpoint and match with the region you've choose to setup your SES:
US East (N. Virginia): email-smtp.us-east-1.amazonaws.com
US West (Oregon): email-smtp.us-west-2.amazonaws.com
EU (Ireland): email-smtp.eu-west-1.amazonaws.com
Hope this helps!

Python 2.6.6 When I get html Source from Website It gives Error

Python 2.6.6 When I get HTML Source from Website It gives Error but it works on 3 version
import urllib
link='https://www.bookabach.co.nz/baches-and-holiday-homes/view/38781/'
f=urllib.urlopen(link)
Error as:
Traceback (most recent call last): File "", line 1,
in
f=urllib.urlopen(link) File "E:\Python26\lib\urllib.py", line 86, in urlopen
return opener.open(url) File "E:\Python26\lib\urllib.py", line 207, in open
return getattr(self, name)(url) File "E:\Python26\lib\urllib.py", line 441, in open_https
h.endheaders() File "E:\Python26\lib\httplib.py", line 908, in endheaders
self._send_output() File "E:\Python26\lib\httplib.py", line 780, in _send_output
self.send(msg) File "E:\Python26\lib\httplib.py", line 739, in send
self.connect() File "E:\Python26\lib\httplib.py", line 1116, in connect
self.sock = ssl.wrap_socket(sock, self.key_file, self.cert_file) File "E:\Python26\lib\ssl.py", line 338, in
wrap_socket
suppress_ragged_eofs=suppress_ragged_eofs) File "E:\Python26\lib\ssl.py", line 120, in init
self.do_handshake() File "E:\Python26\lib\ssl.py", line 279, in do_handshake
self._sslobj.do_handshake() IOError: [Errno socket error] [Errno 1] _ssl.c:490: error:1407742E:SSL
routines:SSL23_GET_SERVER_HELLO:tlsv1 alert protocol version
You may just need to disable SSL verification as you're attempting to reach the site over HTTPS.
Similar issue solved here with urllib.

httpd does not appear to be running and proxying cobbler, or SELinux is in the way

I am using ubuntu.
While doing cobbler check I am getting the following error message.
httpd does not appear to be running and proxying cobbler, or SELinux is in the way. Original traceback:
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/cobbler/cli.py", line 252, in check_setup
s.ping()
File "/usr/lib/python2.7/xmlrpclib.py", line 1224, in __call__
return self.__send(self.__name, args)
File "/usr/lib/python2.7/xmlrpclib.py", line 1578, in __request
verbose=self.__verbose
File "/usr/lib/python2.7/xmlrpclib.py", line 1264, in request
return self.single_request(host, handler, request_body, verbose)
File "/usr/lib/python2.7/xmlrpclib.py", line 1292, in single_request
self.send_content(h, request_body)
File "/usr/lib/python2.7/xmlrpclib.py", line 1439, in send_content
connection.endheaders(request_body)
File "/usr/lib/python2.7/httplib.py", line 969, in endheaders
self._send_output(message_body)
File "/usr/lib/python2.7/httplib.py", line 829, in _send_output
self.send(msg)
File "/usr/lib/python2.7/httplib.py", line 791, in send
self.connect()
File "/usr/lib/python2.7/httplib.py", line 772, in connect
self.timeout, self.source_address)
File "/usr/lib/python2.7/socket.py", line 571, in create_connection
raise err
error: [Errno 111] Connection refused
Changes I have done on the file /etc/cobbler/settings is
server: 172.17.4.61 ( my local IP)
The following line was missing in the file /etc/apache2/apache2.conf
Include conf.d/
Adding the above line to the Apache config file, fixes the issue.

IOError: [Errno socket error] [Errno 1] _ssl.c:507: error:140770FC:SSL routines:SSL23_GET_SERVER_HELLO:unknown protocol

below is my code i am using to scrap some web page
i am using python in windows 8
import urllib
import re
htmlfile = urllib.urlopen("https://finance.yahoo.com/q?s=aapl&ql=1")
htmltext = htmlfile.read()
regex='<span id="yfs_l84_aapl">(.+?)</span>'
pattern = re.compile(regex)
price = re.findall(pattern,htmltext)
print price
error i am getting
Traceback (most recent call last):
File "C:\Python27\web.py", line 4, in
htmlfile = urllib.urlopen("https://finance.yahoo.com/q?s=aapl&ql=1")
File "C:\Python27\lib\urllib.py", line 87, in urlopen
return opener.open(url)
File "C:\Python27\lib\urllib.py", line 208, in open
return getattr(self, name)(url)
File "C:\Python27\lib\urllib.py", line 437, in open_https
h.endheaders(data)
File "C:\Python27\lib\httplib.py", line 969, in endheaders
self._send_output(message_body)
File "C:\Python27\lib\httplib.py", line 829, in _send_output
self.send(msg)
File "C:\Python27\lib\httplib.py", line 791, in send
self.connect()
File "C:\Python27\lib\httplib.py", line 1176, in connect
self.sock = ssl.wrap_socket(sock, self.key_file, self.cert_file)
File "C:\Python27\lib\ssl.py", line 387, in wrap_socket
ciphers=ciphers)
File "C:\Python27\lib\ssl.py", line 143, in init
self.do_handshake()
File "C:\Python27\lib\ssl.py", line 305, in do_handshake
self._sslobj.do_handshake()
IOError: [Errno socket error] [Errno 1] _ssl.c:507: error:140770FC:SSL routines:SSL23_GET_SERVER_HELLO:unknown protocol
how to debug this error
use inspect element > go to console > check if any errors in script > manage them > if problem still persists go to network option > now reload the page and check the flow of information > and rebuilt where info. flow is stopped or unexpected.
hope this will solve your problem.
i found an another answer my self
use inspect element > go to console > check if any errors in script > manage them > if problem still persists go to network option > now reload the page and check the flow of information > and rebuilt where info. flow is stopped or unexpected.