python fabric execute error - python

I execute fabric with both fab.exe and run python script directly.
But it shows error.
My PC is Windows 7, Python 2.7.13
Traceback (most recent call last):
File "C:\fabric_test.py", line 3, in <module>
from fabric.api import run,env,execute,task
File "C:\Python27\lib\site-packages\fabric\api.py", line 10, in <module>
from fabric.context_managers import (cd, hide, settings, show, path, prefix,
File "C:\Python27\lib\site-packages\fabric\context_managers.py", line 41, in <module>
from fabric.state import output, win32, connections, env
File "C:\Python27\lib\site-packages\fabric\state.py", line 9, in <module>
from fabric.network import HostConnectionCache, ssh
File "C:\Python27\lib\site-packages\fabric\network.py", line 24, in <module>
import paramiko as ssh
File "C:\Python27\lib\site-packages\paramiko\__init__.py", line 31, in <module>
from paramiko.transport import SecurityOptions, Transport
File "C:\Python27\lib\site-packages\paramiko\transport.py", line 56, in <module>
from paramiko.dsskey import DSSKey
File "C:\Python27\lib\site-packages\paramiko\dsskey.py", line 27, in <module>
from cryptography.hazmat.primitives.asymmetric.utils import (
File "C:\Python27\lib\site-packages\cryptography\hazmat\primitives\asymmetric\utils.py", line 9, in <module>
from asn1crypto.algos import DSASignature
File "C:\Python27\lib\site-packages\asn1crypto\algos.py", line 23, in <module>
from ._int import fill_width
File "C:\Python27\lib\site-packages\asn1crypto\_int.py", line 56, in <module>
from ._perf._big_num_ctypes import libcrypto
File "C:\Python27\lib\site-packages\asn1crypto\_perf\_big_num_ctypes.py", line 31, in <module>
libcrypto_path = find_library('crypto')
File "C:\Python27\lib\ctypes\util.py", line 53, in find_library
fname = os.path.join(directory, name)
File "C:\Python27\lib\ntpath.py", line 85, in join
result_path = result_path + p_path
UnicodeDecodeError: 'ascii' codec can't decode byte 0xbc in position 21: ordinal not in range(128)
what's the problem?

I hack the C:\Python27\lib\ntpath.py file.
add this source code to header of that file. (17 line)
reload(sys)
sys.setdefaultencoding('euc-kr')
then, error disappear. fabric works fine.
but i don't know reason.
what's the problem in my pc?
I want solve this problem without hack.

Related

GOT TypeError: deprecated() got an unexpected keyword argument 'name' in boto3

Boto3 was running successfully the day before but when i ran today i am getting these errors
import boto3
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/root1/.local/lib/python3.10/site-packages/boto3/__init__.py", line 16, in <module>
from boto3.session import Session
File "/home/root1/.local/lib/python3.10/site-packages/boto3/session.py", line 17, in <module>
import botocore.session
File "/home/root1/.local/lib/python3.10/site-packages/botocore/session.py", line 29, in <module>
import botocore.credentials
File "/home/root1/.local/lib/python3.10/site-packages/botocore/credentials.py", line 35, in <module>
from botocore.config import Config
File "/home/root1/.local/lib/python3.10/site-packages/botocore/config.py", line 16, in <module>
from botocore.endpoint import DEFAULT_TIMEOUT, MAX_POOL_CONNECTIONS
File "/home/root1/.local/lib/python3.10/site-packages/botocore/endpoint.py", line 24, in <module>
from botocore.awsrequest import create_request_object
File "/home/root1/.local/lib/python3.10/site-packages/botocore/awsrequest.py", line 24, in <module>
import botocore.utils
File "/home/root1/.local/lib/python3.10/site-packages/botocore/utils.py", line 32, in <module>
import botocore.httpsession
File "/home/root1/.local/lib/python3.10/site-packages/botocore/httpsession.py", line 28, in <module>
from urllib3.contrib.pyopenssl import orig_util_SSLContext as SSLContext
File "/usr/lib/python3/dist-packages/urllib3/contrib/pyopenssl.py", line 50, in <module>
import OpenSSL.SSL
File "/home/root1/.local/lib/python3.10/site-packages/OpenSSL/__init__.py", line 8, in <module>
from OpenSSL import SSL, crypto
File "/home/root1/.local/lib/python3.10/site-packages/OpenSSL/SSL.py", line 19, in <module>
from OpenSSL.crypto import (
File "/home/root1/.local/lib/python3.10/site-packages/OpenSSL/crypto.py", line 3224, in <module>
utils.deprecated(
TypeError: deprecated() got an unexpected keyword argument 'name'
i tried uninstalling and reinstalling also tried out installing specific version
still getting an error
i am using it on ubuntu 22.0
the python version i am running
Python 3.10.6

I am testing HTTP get method but there is an error "No module named ASCII"?

ASCII is installed but still getting this error. I tested by importing all the libraries in the error msg but could not solve it.
Complete Error Message here.
Traceback (most recent call last):
File "re.py", line 1, in <module>
import requests,compile, ASCII
File "C:\Program Files\Python37\lib\site-packages\requests\__init__.py", line 43, in <module>
import urllib3
File "C:\Program Files\Python37\lib\site-packages\urllib3\__init__.py", line 7, in <module>
from .connectionpool import HTTPConnectionPool, HTTPSConnectionPool, connection_from_url
File "C:\Program Files\Python37\lib\site-packages\urllib3\connectionpool.py", line 3, in <module>
import logging
File "C:\Program Files\Python37\lib\logging\__init__.py", line 26, in <module>
import sys, os, time, io, traceback, warnings, weakref, collections.abc
File "C:\Program Files\Python37\lib\traceback.py", line 5, in <module>
import linecache
File "C:\Program Files\Python37\lib\linecache.py", line 11, in <module>
import tokenize
File "C:\Program Files\Python37\lib\tokenize.py", line 33, in <module>
import re
File "C:\Users\naeem\Desktop\re.py", line 1, in <module>
import requests,compile, ASCII
ModuleNotFoundError: No module named 'ASCII'
Python Code I am running is here:
import requests,compile, ASCII
def main():
res = requests.get("https://www.google.com/")
print(res.text)
if __name__=="__main__":
main()
Can anybody help me out please?
ModuleNotFoundError: No module named 'ASCII'
This means that don't exist a module named 'ASCII'.
Maybe it's useful curses.ascii
so:
import curses.ascii
You can find Documentation here:
https://docs.python.org/3/library/curses.ascii.html

Updated AWS CLI for EC2 via Ansible throws boto errors

I'm seeing an odd issue where after updating the AWS CLI from 1.10.1 to 1.10.60, running ec2 commands through Ansible no longer works.
i.e., running:
local_action: "shell AWS_PROFILE=dev-aws aws ec2 describe-instances --debug --filters 'Name=instance-state-name,Values=running' 'Name=tag:Role,Values=ms_bastion'"
... through Ansible throws this stack trace:
File \"/usr/local/bin/aws\", line 23, in main
return awscli.clidriver.main()
File \"/usr/local/lib/python2.7/site-packages/awscli/clidriver.py\", line 49, in main
driver = create_clidriver()
File \"/usr/local/lib/python2.7/site-packages/awscli/clidriver.py\", line 58, in create_clidriver
event_hooks=emitter)
File \"/usr/local/lib/python2.7/site-packages/awscli/plugin.py\", line 44, in load_plugins
modules = _import_plugins(plugin_mapping)
File \"/usr/local/lib/python2.7/site-packages/awscli/plugin.py\", line 61, in _import_plugins
module = __import__(path, fromlist=[module])
File \"/usr/local/lib/python2.7/site-packages/awscli/handlers.py\", line 66, in <module>
from awscli.customizations.s3.s3 import s3_plugin_initialize
File \"/usr/local/lib/python2.7/site-packages/awscli/customizations/s3/s3.py\", line 15, in <module>
from awscli.customizations.s3.subcommands import ListCommand, WebsiteCommand, \\
File \"/usr/local/lib/python2.7/site-packages/awscli/customizations/s3/subcommands.py\", line 24, in <module>
from awscli.customizations.s3.fileinfobuilder import FileInfoBuilder
File \"/usr/local/lib/python2.7/site-packages/awscli/customizations/s3/fileinfobuilder.py\", line 13, in <module>
from awscli.customizations.s3.fileinfo import FileInfo
File \"/usr/local/lib/python2.7/site-packages/awscli/customizations/s3/fileinfo.py\", line 9, in <module>
from botocore.compat import MD5_AVAILABLE
ImportError: cannot import name MD5_AVAILABLE

What does this capistrano error mean when doing an AWS file fetch via cap tasks?

In my deploy/development.rb, I have the following line:-
set :env_path, 's3api get-object --bucket <bucket_name> --key <file_name> <file_name>'
In my cap file, I have the following task defined:
task :download_configs do
on roles(:all) do
within release_path do
execute :aws, "#{fetch(:env_path)}"
end
end
# on roles(:db) do
# within release_path do
# execute :aws, "#{fetch(:env_path)}"
# end
# end
end
But on cap deploy,I am seeing the following errors:-
cap aborted!
SSHKit::Runner::ExecuteError: Exception while executing as ubuntu#54.213.226.117: aws exit status: 1
aws stdout: Traceback (most recent call last):
File "/usr/bin/aws", line 15, in <module>
import awscli.clidriver
File "/usr/share/awscli/awscli/clidriver.py", line 30, in <module>
from awscli.help import ProviderHelpCommand
File "/usr/share/awscli/awscli/help.py", line 20, in <module>
from docutils.core import publish_string
File "/usr/lib/python3/dist-packages/docutils/core.py", line 20, in <module>
from docutils import frontend, io, utils, readers, writers
File "/usr/lib/python3/dist-packages/docutils/frontend.py", line 41, in <module>
import docutils.utils
File "/usr/lib/python3/dist-packages/docutils/utils/__init__.py", line 20, in <module>
import docutils.io
File "/usr/lib/python3/dist-packages/docutils/io.py", line 18, in <module>
from docutils.utils.error_reporting import locale_encoding, ErrorString, ErrorOutput
File "/usr/lib/python3/dist-packages/docutils/utils/error_reporting.py", line 47, in <module>
locale_encoding = locale.getlocale()[1] or locale.getdefaultlocale()[1]
File "/usr/lib/python3.4/locale.py", line 556, in getdefaultlocale
return _parse_localename(localename)
File "/usr/lib/python3.4/locale.py", line 484, in _parse_localename
raise ValueError('unknown locale: %s' % localename)
ValueError: unknown locale: UTF-8
aws stderr: Nothing written
SSHKit::Command::Failed: aws exit status: 1
aws stdout: Traceback (most recent call last):
File "/usr/bin/aws", line 15, in <module>
import awscli.clidriver
File "/usr/share/awscli/awscli/clidriver.py", line 30, in <module>
from awscli.help import ProviderHelpCommand
File "/usr/share/awscli/awscli/help.py", line 20, in <module>
from docutils.core import publish_string
File "/usr/lib/python3/dist-packages/docutils/core.py", line 20, in <module>
from docutils import frontend, io, utils, readers, writers
File "/usr/lib/python3/dist-packages/docutils/frontend.py", line 41, in <module>
import docutils.utils
File "/usr/lib/python3/dist-packages/docutils/utils/__init__.py", line 20, in <module>
import docutils.io
File "/usr/lib/python3/dist-packages/docutils/io.py", line 18, in <module>
from docutils.utils.error_reporting import locale_encoding, ErrorString, ErrorOutput
File "/usr/lib/python3/dist-packages/docutils/utils/error_reporting.py", line 47, in <module>
locale_encoding = locale.getlocale()[1] or locale.getdefaultlocale()[1]
File "/usr/lib/python3.4/locale.py", line 556, in getdefaultlocale
return _parse_localename(localename)
File "/usr/lib/python3.4/locale.py", line 484, in _parse_localename
raise ValueError('unknown locale: %s' % localename)
ValueError: unknown locale: UTF-8
aws stderr: Nothing written
Please help me identify what is going wrong here!
Shot in the dark (I'm not a Python dev), but you might be able add the following to deploy.rb:
set :default_env, {
'LANG' => 'en_US.UTF-8'
}
Derived mostly from https://github.com/matplotlib/matplotlib/issues/5420#issuecomment-154454607
I would check to see if you can run the command manually on the server. If you cannot, then figure out how to without Capistrano. If you can, perhaps see if there is some configuration in .bashrc or .bash_profile that can be added to the Capistrano config.

Cannot `import smtplib`

When ever I try to import smtplib in the Python interpreter, I get this error:
ImportError: cannot import name fix_eols
How can I fix this?
Edit:
Here is the full stack trace:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/Cellar/python/2.7.10_2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/smtplib.py", line 46, in <module>
import email.utils
File "/usr/local/Cellar/python/2.7.10_2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/email/utils.py", line 32, in <module>
from email._parseaddr import quote
File "/usr/local/Cellar/python/2.7.10_2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/email/_parseaddr.py", line 16, in <module>
import time, calendar
File "/Users/aaronblock/Documents/programming/scripts/calendar.py", line 7, in <module>
File "/usr/local/lib/python2.7/site-packages/apiclient/__init__.py", line 19, in <module>
from googleapiclient import discovery
File "/usr/local/lib/python2.7/site-packages/googleapiclient/discovery.py", line 38, in <module>
from email.generator import Generator
File "/usr/local/Cellar/python/2.7.10_2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/email/generator.py", line 15, in <module>
from email.header import Header
File "/usr/local/Cellar/python/2.7.10_2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/email/header.py", line 16, in <module>
import email.quoprimime
File "/usr/local/Cellar/python/2.7.10_2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/email/quoprimime.py", line 49, in <module>
from email.utils import fix_eols
ImportError: cannot import name fix_eols
Just to point out how to detect this kinds of errors (since it does happen from time to time):
Pay attention to the stacktrace. In this example, the problem can be seen in the line:
File "/Users/aaronblock/Documents/programming/scripts/calendar.py", line 7, in <module>
which certainly indicates wrong file being imported when we're trying to import a system-wide library.
I had a file called "calendar.py" which messes up my Python environment because smtplib needs calendar.py in order to work. Deleting calendar.py solved my problem.

Categories