I have an error when trying to use a Python tool cif2cell. What cif2cell does it take a .cif file in and return a .cell file.
Intro can be found elsewhere about what it is, but its basically a materials modelling tool, and what I'm trying to do is input a .cif file that represents this 'tile' of atoms, and return a .cell file that is a structure of many of these tiles - The supercell.
In my case I'm going for a 5x5x1 supercell, as can be seen.
Here's the terminal command;
$ ./cif2cell -p castep -f 9000046.cif -o structure1.cell --supercell = [5 5 1]
Which is yielding the following error;
Traceback (most recent call last):
File "./cif2cell", line 354, in <module>
supercellmap = safe_matheval(options.supercellmap)
File "/Users/ 'my name' /Desktop/castep-8.0-macosx-intel/utils.py", line 525, in safe_matheval
return eval(sexpr,{"__builtins__":None},safe_dict)
File "<string>", line 1
=
^
SyntaxError: unexpected EOF while parsing
I have seen that the error has been come across by many writing simple programs, but I have not found any resolutions/examples where a tool has been queried.
Related
I am able to compile an invoice with the following command:
pandoc details.yml -o output.pdf --template=invoice.tex --latex-engine=xelatex
But when I write the same thing in Python, I get an error complaning about the input format:
>>> pypandoc.convert_file('details.yml', 'pdf', outputfile='pyout.pdf', extra_args=['--latex-engine=xelatex', '--template=invoice.tex'])
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python3.6/site-packages/pypandoc/__init__.py", line 140, in convert_file
outputfile=outputfile, filters=filters)
File "/usr/local/lib/python3.6/site-packages/pypandoc/__init__.py", line 262, in _convert_input
format, to = _validate_formats(format, to, outputfile)
File "/usr/local/lib/python3.6/site-packages/pypandoc/__init__.py", line 223, in _validate_formats
_get_base_format(format), ', '.join(from_formats)))
RuntimeError: Invalid input format! Got "yml" but expected one of
these: commonmark, docbook, docx, epub, haddock, html, json, latex, markdown, markdown_github, markdown_mmd, markdown_phpextra, markdown_strict, mediawiki, native, odt, opml, org, rst, t2t, textile, twiki
What am I doing wrong here? Why is yml not accepted?
Figured it out by reading the source.
So it turns out that this is due to a design decision made by the pypandoc developers. The program infers the type of the input from the file extension, so the only way to pass a yaml file is to rename it with a .md-extension.
https://github.com/bebraw/pypandoc/blob/ffe82646d2ab6cc4e732960a1e1af6bfcb760bb1/pypandoc/init.py#L202
I've been migrating some Python 2.7.11 code to 3.5.1 after running into trouble with unicode. This was the last straw - since I started using the venv module there's no reason to be on 2.7 just because someone doesn't like 3!
The problem occurs while trying to run a one-way sync (ie. downloading changes only).
Here is the full error message, paths shortened:
Traceback (most recent call last):
File "%SCRIPT%.py", line 209, in <module>
updated_schedules = dbx_sync.One_Way_Sync(config['Dropbox Parameters']['Directory'], config['Dropbox Parameters']['Base Path'])
File "%COMMON_PATH%\modules\dropbox_sync_schedules.py", line 62, in One_Way_Sync
result = client.delta(cursor, base_path)
File "%COMMON_PATH%\env-home\lib\site-packages\dropbox\client.py", line 569, in delta
return self.rest_client.POST(url, params, headers)
File "%COMMON_PATH%\env-home\lib\site-packages\dropbox\rest.py", line 322, in POST
return cls.IMPL.POST(*n, **kw)
File "%COMMON_PATH%\env-home\lib\site-packages\dropbox\rest.py", line 260, in POST
is_json_request=is_json_request)
File "%COMMON_PATH%\env-home\lib\site-packages\dropbox\rest.py", line 235, in request
raise ErrorResponse(r, r.read())
dropbox.rest.ErrorResponse: [400] 'Invalid "cursor" parameter: u"b\'\'"'
Searching for "invalid cursor parameter" wasn't any help, so I thought I'd come here.
u"b\'\'" is the key here. I just couldn't understand how that representation had ended up being sent as a string.
The issue was in reading the old cursor from a file (which for this example is empty): in Python 2 I had opened the file in mode rb - in Python 3 just r is all that's required, and everything works.
Hurrah!
I was looking for some help with a program I am writing for personal use. It is supposed to export a movie's name and rating (stored in a dictionary) to an external file (file.txt) and then load it at the start of every run. It should also export a movie's name and review (also a dictionary) to another external file (review.txt). I get an error on the line for reading the file.txt and putting it in base. Any clues?
base = {}
#Open and write info to base
with open('file.txt','r') as f:
# Error here :(
base = eval(f.read())
error message:
Traceback (most recent call last):
File "/Users/Will/Documents/movie_database.py", line 18, in <module>
base = eval(f.read())
File "<string>", line 0
^
SyntaxError: unexpected EOF while parsing
Your file is empty, so eval() throws an exception because no Python expression was found:
>>> eval('') # empty string
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<string>", line 0
^
SyntaxError: unexpected EOF while parsing
You shouldn't be using eval() in the first place however, the security implications are terrifying here. Someone that can fool you into loading an arbitrary file can now take over your Python process, and turn your machine into a spam bot zombie.
json or shelve (or directly using pickle, although that has security implications as well) would offer you better and more robust serialisation options. You could also look into using sqlite3 for a SQL database option.
I've got PyPDF2 lib from here:
https://github.com/mstamy2/PyPDF2/tree/Python3-3
When trying to run script "Example 1:" from from there see it:
PyPDF2 python versions (2.5 - 3.3) compatibility branch
Traceback (most recent call last):
File "1.py", line 6, in <module>
input1 = PdfFileReader(open("document1.pdf", "rb"))
File "C:\Python33\lib\site-packages\PyPDF2\pdf.py", line 595, in __init__
self.read(stream)
File "C:\Python33\lib\site-packages\PyPDF2\pdf.py", line 1097, in read
streamData = StringIO(xrefstream.getData())
TypeError: initial_value must be str or None, not bytes
What is wrong?
It was a problem related to the compatibility within PyPDF2 and Python 3.
In my case, I have solved it by replacing pdf.py and utils.py with the ones you will find here, where they basically control if you are running Python 3 and, in case you are, receive data as bytes instead of strings.
Using OS X 10.6.8, libxml 2-2.7.8, libxslt-1.1.26, and python 2.6, I'm trying to run the tumblrRestore.py script linked here:
https://github.com/hughsaunders/Tumblr-Restore/blob/master/tumblrRestore.py
It ran successfully and restored 76 posts before crashing.
However on second run I got an ExpatError: no element found, and have not been able to run it successfully since - it always produces this same error now. Error text:
Tumblr Restore
Traceback (most recent call last):
File "tumblrRestore.py", line 264, in <module>
cli.start()
File "tumblrRestore.py", line 232, in start
bp.parse()
File "tumblrRestore.py", line 51, in parse
postelement=ElementTree.fromstring(xml_string)
File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/xml/etree/ElementTree.py", line 964, in XM
return parser.close()
File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/xml/etree/ElementTree.py", line 1254, in close
self._parser.Parse("", 1) # end of data
xml.parsers.expat.ExpatError: no element found: line 1, column 0
I'm wondering whether I have the wrong or competing or outdated versions of python or lxml, though that still doesn't explain why the script ran successfully once.
Complete newbie, any advice appreciated.
Check your extract_xml_string method of BackupParser class. It definitely returns empty string, because your begin_re regular expresssion doesn't match xml header.
Try the next one:
begin_re = re.compile("<\? xml .*\?>")