ansible unexpected exception no escaped character - python

I am fairly new to Ansible and to configuration management tools in general. I've been playing around with it for the last two days and for the life of me I can't get past typing out ansible testserver. It comes back with an error message that says Unexpected Exception: No escaped character. The full error message is:
mac-dgarcia:playbooks dgarcia$ ansible testserver -i hosts -m ping -vvv
Using /Users/dgarcia/Documents/Playbooks/ansible.cfg as config file
Unexpected Exception: No escaped character
the full traceback was:
Traceback (most recent call last):
File "/Users/dgarcia/Documents/Playbooks/ansible/bin/ansible", line 79, in <module>
sys.exit(cli.run())
File "/Users/dgarcia/Documents/Playbooks/ansible/lib/ansible/cli/adhoc.py", line 106, in run
inventory = Inventory(loader=loader, variable_manager=variable_manager, host_list=self.options.inventory)
File "/Users/dgarcia/Documents/Playbooks/ansible/lib/ansible/inventory/__init__.py", line 135, in __init__
self.parser = InventoryParser(filename=host_list)
File "/Users/dgarcia/Documents/Playbooks/ansible/lib/ansible/inventory/ini.py", line 45, in __init__
self._parse()
File "/Users/dgarcia/Documents/Playbooks/ansible/lib/ansible/inventory/ini.py", line 49, in _parse
self._parse_base_groups()
File "/Users/dgarcia/Documents/Playbooks/ansible/lib/ansible/inventory/ini.py", line 107, in _parse_base_groups
tokens = shlex.split(line)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/shlex.py", line 279, in split
return list(lex)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/shlex.py", line 269, in next
token = self.get_token()
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/shlex.py", line 96, in get_token
raw = self.read_token()
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/shlex.py", line 191, in read_token
raise ValueError, "No escaped character"
ValueError: No escaped character
Have searched everywhere I can on Google and came back with nothing. Any ideas?

I had the same issue and changing my host file to have only one line fixed the problem.
My host file looks like the following:
testserver ansible_ssh_host=128.0.0.1 ansible_ssh_port=2222 \
ansible_ssh_user=vagrant \
ansible_ssh_private_key_file=/home/bibryam/Desktop/.vagrant/machines/fabric/virtualbox/private_key

Related

trying to import pyautogui on wsl ubuntu throwing KEYERROR :DISPLAY

I know this question is a clone of many similar questions but none of them had any answers except this one. I tried everything that where suggested in that question including putting "DISPLAY=:0" in my bashrc(zshrc in my case) and running python with DISPLAY=:0 python or using os.environ['DISPLAY'] = ':0' but every time result was same, it throw me even longer but same error for every 3 solutions.
update:
running echo $DISPLAY returns nothing and running xhost + on my terminal throws zsh: command not found: xhost (since I saw first one was asked from person with a problem same as me and second one was suggested as an temporary solution)
the error is :
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/pedram/anaconda3/envs/PyBot/lib/python3.10/site-packages/pyautogui/__init__.py", line 249, in <module>
import mouseinfo
File "/home/pedram/anaconda3/envs/PyBot/lib/python3.10/site-packages/mouseinfo/__init__.py", line 223, in <module>
_display = Display(os.environ['DISPLAY'])
File "/usr/local/lib/python3.8/dist-packages/Xlib/display.py", line 80, in __init__
self.display = _BaseDisplay(display)
File "/usr/local/lib/python3.8/dist-packages/Xlib/display.py", line 62, in __init__
display.Display.__init__(*(self, ) + args, **keys)
File "/usr/local/lib/python3.8/dist-packages/Xlib/protocol/display.py", line 58, in __init__
self.socket = connect.get_socket(name, host, displayno)
File "/usr/local/lib/python3.8/dist-packages/Xlib/support/connect.py", line 76, in get_socket
return mod.get_socket(dname, host, dno)
File "/usr/local/lib/python3.8/dist-packages/Xlib/support/unix_connect.py", line 78, in get_socket
raise error.DisplayConnectionError(dname, str(val))
Xlib.error.DisplayConnectionError: Can't connect to display ":0": [Errno 2] No such file or directory

Issue with adding a "#" sign using Ansible lineinfile module

I am trying to add a # sign in front of a line under /etc/auto.master file as follow
name: Set auto.master step 1
lineinfile:
path: /etc/auto.master
regexp: '^+auto.master'
line: '^#+auto.master'
However, when I run my playbook, this is what I get
FAILED! => {"changed": false, "module_stderr": "Shared connection to ifmliae1p.bbh.com closed.\r\n", "module_stdout": "Traceback (most recent call last):\r\n 5.94-16341-164301267793697/AnsiballZ_lineinfile.py\", line 102, in \r\n _ansiballz_main()\r\n File \"/root/.ansible/tmp/ansible-tmp-1590180565.94-16341-164301267793697/Ansibal\r\n invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)\r\n File \"/root/.ansible/tmp/ansible-tmp-1590180565.94-16341-164301267793697/AnsiballZ_lineinfile.py\", line 40, in invokele.modules.files.lineinfile', init_globals=None, run_name='main', alter_sys=True)\r\n File \"/usr/lib64/python2.7/runpy.py\", line 176, in run_module\r\n fname, loader, pkg_name)\ne 82, in _run_module_code\r\n mod_name, mod_fname, mod_loader, pkg_name)\r\n File \"/usr/lib64/python2.7/runpy.py\", line 72, in _run_code\r\n exec code in run_globals\r\n File _lineinfile_payload.zip/ansible/modules/files/lineinfile.py\", line 573, in \r\n File \"/tmp/ansible_lineinfile_payload_KyHa6O/ansible_lineinfile_payload.zip/ansible/modules/file\"/tmp/ansible_lineinfile_payload_KyHa6O/ansible_lineinfile_payload.zip/ansible/modules/files/lineinfile.py\", line 277, in present\r\n File \"/usr/lib64/python2.7/re.py\", line 190, in r\n File \"/usr/lib64/python2.7/re.py\", line 242, in _compile\r\n raise error, v # invalid expression\r\nsre_constants.error: nothing to repeat\r\n", "msg": "MODULE FAILURE\nSee stdo
I am not sure why it doesn't work. The examples on ansible documentation page seems to work fine.
Apparently, my thinking was going sideways. I thought this line was the issue
line: '^#+auto.master'
But this is the culprit
regexp: '^+auto.master'
The plus sign has to be escaped like so.
regexp: '^\+auto.master'
line: '#+auto.master'
Some possible issues:
YAML file wrong indentation
unescaped characters

Issue while installing pip python

i installed python 3.7.2 still pip was not installed,for pip there must be pip.exe in folder script in directory where python is installed but in my device there nothing in it.
later i tried to install it by running get-pip.py but it throws an exception in command prompt
Command prompt throws exception :-
Installing collected packages: pip, setuptools, wheel Exception: Traceback (most recent call last):
File "C:\Users\Del$in\AppData\Local\Programs\Python\Python37\lib\distutils\uti l.py", line 187, in subst_vars return re.sub(r'\$([a-zA-Z_][a-zA-Z_0-9]*)', _subst, s)
File "C:\Users\Del$in\AppData\Local\Programs\Python\Python37\lib\re.py", line 192, in sub return _compile(pattern, flags).sub(repl, string, count)
File "C:\Users\Del$in\AppData\Local\Programs\Python\Python37\lib\distutils\uti l.py", line 184, in _subst return os.environ[var_name]
File "C:\Users\Del$in\AppData\Local\Programs\Python\Python37\lib\os.py", line 678, in getitem raise KeyError(key) from None KeyError: 'in'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\Del$in\AppData\Local\Temp\tmpwzho1r2w\pip.zip\pip_internal\cli \base_command.py", line 179, in main status = self.run(options, args)
File "C:\Users\Del$in\AppData\Local\Temp\tmpwzho1r2w\pip.zip\pip_internal\com mands\install.py", line 393, in run use_user_site=options.use_user_site,
File "C:\Users\Del$in\AppData\Local\Temp\tmpwzho1r2w\pip.zip\pip_internal\req __init__.py", line 57, in install_given_reqs **kwargs
File "C:\Users\Del$in\AppData\Local\Temp\tmpwzho1r2w\pip.zip\pip_internal\req \req_install.py", line 913, in install use_user_site=use_user_site, pycompile=pycompile,
File "C:\Users\Del$in\AppData\Local\Temp\tmpwzho1r2w\pip.zip\pip_internal\req \req_install.py", line 445, in move_wheel_files warn_script_location=warn_script_location,
File "C:\Users\Del$in\AppData\Local\Temp\tmpwzho1r2w\pip.zip\pip_internal\whe el.py", line 320, in move_wheel_files prefix=prefix,
File "C:\Users\Del$in\AppData\Local\Temp\tmpwzho1r2w\pip.zip\pip_internal\loc ations.py", line 180, in distutils_scheme i.finalize_options()
File "C:\Users\Del$in\AppData\Local\Programs\Python\Python37\lib\distutils\com mand\install.py", line 307, in finalize_options self.expand_basedirs()
File "C:\Users\Del$in\AppData\Local\Programs\Python\Python37\lib\distutils\com mand\install.py", line 475, in expand_basedirs self._expand_attrs(['install_base', 'install_platbase', 'root'])
File "C:\Users\Del$in\AppData\Local\Programs\Python\Python37\lib\distutils\com mand\install.py", line 469, in _expand_attrs val = subst_vars(val, self.config_vars)
File "C:\Users\Del$in\AppData\Local\Programs\Python\Python37\lib\distutils\uti l.py", line 189, in subst_vars raise ValueError("invalid variable '$%s'" % var) ValueError: invalid variable '$'in''
I'm certain that your username is the reason for this error. Python is trying to create a string of your username but the $ is causing issues. You can see this in the line ValueError: invalid variable '$'in''. Although there are other solutions, changing your username to DelSin will prevent many other headaches too.
From the code in distutils/utils.py:
def subst_vars (s, local_vars):
"""Perform shell/Perl-style variable substitution on 'string'. Every
occurrence of '$' followed by a name is considered a variable, and
variable is substituted by the value found in the 'local_vars'
dictionary, or in 'os.environ' if it's not in 'local_vars'.
'os.environ' is first checked/augmented to guarantee that it contains
certain values: see 'check_environ()'. Raise ValueError for any
variables not found in either 'local_vars' or 'os.environ'.
"""
This is utilizing the utility that's quite common in bash/Perl scripting, where you can substitute in a value using $:
SOMEPATH='$HOME/somefolder'
echo($SOMEPATH)
# '/path/to/somefolder'
Your username, unfortunately, mimics this and will cause problems until it is changed

Django - ValueError: plural forms expression could be dangerous

I'm working with Django 1.9 in Microsoft Visual Studio. Also I'm using a virtual env, where all the needed python packages are installed. When I try to compile messages in order to add translation function to the site, the following error is raised:
ValueError: plural forms expression could be dangerous
Update 1. Stacktrace:
Internal Server Error: /
Traceback (most recent call last):
File "C:\path-to-project\env\lib\site-packages\django\core\handlers\base.py", line 123, in get_response
response = middleware_method(request)
File "C:\path-to-project\env\lib\site-packages\django\middleware\locale.py", line 26, in process_request
translation.activate(language)
File "C:\path-to-project\env\lib\site-packages\django\utils\translation\__init__.py", line 154, in activate
return _trans.activate(language)
File "C:\path-to-project\env\lib\site-packages\django\utils\translation\trans_real.py", line 216, in activate
_active.value = translation(language)
File "C:\path-to-project\env\lib\site-packages\django\utils\translation\trans_real.py", line 205, in translation
_translations[language] = DjangoTranslation(language)
File "C:\path-to-project\env\lib\site-packages\django\utils\translation\trans_real.py", line 114, in __init__
self._add_installed_apps_translations()
File "C:\path-to-project\env\lib\site-packages\django\utils\translation\trans_real.py", line 160, in _add_installed_apps_translations
translation = self._new_gnu_trans(localedir)
File "C:\path-to-project\env\lib\site-packages\django\utils\translation\trans_real.py", line 140, in _new_gnu_trans
fallback=use_null_fallback)
File "C:\Python27\Lib\gettext.py", line 481, in translation
t = _translations.setdefault(key, class_(fp))
File "C:\Python27\Lib\gettext.py", line 182, in __init__
self._parse(fp)
File "C:\Python27\Lib\gettext.py", line 318, in _parse
self.plural = c2py(plural)
File "C:\Python27\Lib\gettext.py", line 95, in c2py
raise ValueError, 'plural forms expression could be dangerous'
ValueError: plural forms expression could be dangerous
I've read about that (plural forms expression could be dangerous and Django: gettext raises ValueError: 'plural forms expression could be dangerous'), but the only solution I found is to remove lines referred to plural translations, for example:
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
If I remove those lines in my translations files, it still raises the same error, because it takes into account other files located at the virtual env.
Update 2: If I run the server from the command line, using
python manage.py runserver
there's no problem, everything is going right. However, when I run the project from Visual Studio, the error is raised.
Is there any way to solve this problem?
Thanks in advance.

Scrapy: Unhandled Error

My scraper runs fine for about an hour. After a while I start seeing these errors:
2014-01-16 21:26:06+0100 [-] Unhandled Error
Traceback (most recent call last):
File "/home/scraper/.fakeroot/lib/python2.7/site-packages/Scrapy-0.20.2-py2.7.egg/scrapy/crawler.py", line 93, in start
self.start_reactor()
File "/home/scraper/.fakeroot/lib/python2.7/site-packages/Scrapy-0.20.2-py2.7.egg/scrapy/crawler.py", line 130, in start_reactor
reactor.run(installSignalHandlers=False) # blocking call
File "/home/scraper/.fakeroot/lib/python2.7/site-packages/twisted/internet/base.py", line 1192, in run
self.mainLoop()
File "/home/scraper/.fakeroot/lib/python2.7/site-packages/twisted/internet/base.py", line 1201, in mainLoop
self.runUntilCurrent()
--- <exception caught here> ---
File "/home/scraper/.fakeroot/lib/python2.7/site-packages/twisted/internet/base.py", line 824, in runUntilCurrent
call.func(*call.args, **call.kw)
File "/home/scraper/.fakeroot/lib/python2.7/site-packages/Scrapy-0.20.2-py2.7.egg/scrapy/utils/reactor.py", line 41, in __call__
return self._func(*self._a, **self._kw)
File "/home/scraper/.fakeroot/lib/python2.7/site-packages/Scrapy-0.20.2-py2.7.egg/scrapy/core/engine.py", line 106, in _next_request
if not self._next_request_from_scheduler(spider):
File "/home/scraper/.fakeroot/lib/python2.7/site-packages/Scrapy-0.20.2-py2.7.egg/scrapy/core/engine.py", line 132, in _next_request_from_scheduler
request = slot.scheduler.next_request()
File "/home/scraper/.fakeroot/lib/python2.7/site-packages/Scrapy-0.20.2-py2.7.egg/scrapy/core/scheduler.py", line 64, in next_request
request = self._dqpop()
File "/home/scraper/.fakeroot/lib/python2.7/site-packages/Scrapy-0.20.2-py2.7.egg/scrapy/core/scheduler.py", line 94, in _dqpop
d = self.dqs.pop()
File "/home/scraper/.fakeroot/lib/python2.7/site-packages/queuelib/pqueue.py", line 43, in pop
m = q.pop()
File "/home/scraper/.fakeroot/lib/python2.7/site-packages/Scrapy-0.20.2-py2.7.egg/scrapy/squeue.py", line 18, in pop
s = super(SerializableQueue, self).pop()
File "/home/scraper/.fakeroot/lib/python2.7/site-packages/queuelib/queue.py", line 157, in pop
self.f.seek(-size-self.SIZE_SIZE, os.SEEK_END)
exceptions.IOError: [Errno 22] Invalid argument
What could possibly be causing this? My version is 0.20.2. Once I get this error, scrapy stops doing anything. Even if I stop and run it again (using a JOBDIR directory), it still gives me these errors. I need to delete the job directory and start over if I need to get rid of these errors.
Try this:
Ensure that you're running latest Scrapy version (current: 0.24)
Search inside the resumed folder, and backup the file requests.seen
After backed up, remove the scrapy job folder
Start the crawl resuming with JOBDIR= option again
Stop the crawl
Replace the newly created requests.seen with previously backed up
Start crawl again

Categories

Resources