While reading file on Python, I got a UnicodeDecodeError. What can I do to resolve this?

Try: enc=”utf-8″ log = open(‘/Users/Owner/Desktop/Exodus Logs/DIRTYLOGS/serverlog_20130430_00.15.21.txt’, ‘r’, encoding=enc) if it won’t work try: enc=”utf-16″ log = open(‘/Users/Owner/Desktop/Exodus Logs/DIRTYLOGS/serverlog_20130430_00.15.21.txt’, ‘r’, encoding=enc) you could also try it with enc=”iso-8859-15″ also try: enc=”cp437″ wich is very old but it also has the “ü” at 0x81 wich would fit to the string “üßer” wich I found on the homepage … Read more

How to use Django’s assertJSONEqual to verify response of view returning JsonResponse

It looks like you’re working with Python 3 so you’ll need to turn response.content into a UTF-8 encoded string before passing it to self.assertJSONEqual: class AddItemToCollectionTest(TestCase): def test_success_when_not_added_before(self): response = self.client.post(‘/add-item-to-collection’) self.assertEqual(response.status_code, 200) self.assertJSONEqual( str(response.content, encoding=’utf8′), {‘status’: ‘success’} ) If you want to simultaneously support both Python 2.7 and Python 3, use the six compatibility … Read more

How to use sys.exit() in Python

I think you can use sys.exit(0) You may check it here in the python 2.7 doc: The optional argument arg can be an integer giving the exit status (defaulting to zero), or another type of object. If it is an integer, zero is considered “successful termination” and any nonzero value is considered “abnormal termination” by … Read more

Run a python script in virtual environment from windows task scheduler

Create batch file with these commands: c:\__full_path_to_virtualenv__\Scripts\activate.bat && python __full_path_to_python_script__.py && means run command2 if command1 completed successfully. Then set that batch file as script to run. You don’t need to set any additional arguments in task scheduler (or you can set them in batch file anyway) and can set Start in if script has … Read more