mirror of
https://github.com/galaxyproject/galaxy.git
synced 2026-09-24 16:30:27 +08:00
Fix `UnicodeDecodeError` exception under Python3
Fix the following exception reported in the startup logs:
```
galaxy.webhooks ERROR 2019-01-15 11:31:18,095 'ascii' codec can't decode byte 0xef in position 8291: ordinal not in range(128)
Traceback (most recent call last):
File "/galaxy/lib/galaxy/webhooks/__init__.py", line 62, in load_webhooks
self.load_webhook_from_config(directory, config_file_path)
File "/galaxy/lib/galaxy/webhooks/__init__.py", line 96, in load_webhook_from_config
webhook.script = file.read()
File "/galaxy_venv3/lib/python3.5/encodings/ascii.py", line 26, in decode
return codecs.ascii_decode(input, self.errors)[0]
UnicodeDecodeError: 'ascii' codec can't decode byte 0xef in position 8291: ordinal not in range(128)
```
Also rename variables from `file` (Python2 standard library function and
class) to `fh`.
This commit is contained in:
@@ -499,12 +499,12 @@ def send_file(start_response, trans, body):
|
||||
return body
|
||||
|
||||
|
||||
def iterate_file(file):
|
||||
def iterate_file(fh):
|
||||
"""
|
||||
Progressively return chunks from `file`.
|
||||
"""
|
||||
while 1:
|
||||
chunk = file.read(CHUNK_SIZE)
|
||||
chunk = fh.read(CHUNK_SIZE)
|
||||
if not chunk:
|
||||
break
|
||||
yield chunk
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
"""
|
||||
This module manages loading of Galaxy webhooks.
|
||||
"""
|
||||
import io
|
||||
import logging
|
||||
import os
|
||||
|
||||
@@ -64,8 +65,8 @@ class WebhooksRegistry(object):
|
||||
log.exception(e)
|
||||
|
||||
def load_webhook_from_config(self, webhook_dir, config_file_path):
|
||||
with open(config_file_path) as file:
|
||||
config = yaml.safe_load(file)
|
||||
with open(config_file_path) as fh:
|
||||
config = yaml.safe_load(fh)
|
||||
|
||||
weight = config.get('weight', 1)
|
||||
if weight < 1:
|
||||
@@ -83,8 +84,8 @@ class WebhooksRegistry(object):
|
||||
# single file
|
||||
try:
|
||||
styles_file = os.path.join(webhook_dir, 'styles.css')
|
||||
with open(styles_file, 'r') as file:
|
||||
webhook.styles = file.read().replace('\n', '')
|
||||
with open(styles_file, 'r') as fh:
|
||||
webhook.styles = fh.read().replace('\n', '')
|
||||
except IOError:
|
||||
pass
|
||||
|
||||
@@ -92,8 +93,8 @@ class WebhooksRegistry(object):
|
||||
# single file
|
||||
try:
|
||||
script_file = os.path.join(webhook_dir, 'script.js')
|
||||
with open(script_file, 'r') as file:
|
||||
webhook.script = file.read()
|
||||
with io.open(script_file, 'r', encoding='utf-8') as fh:
|
||||
webhook.script = fh.read()
|
||||
except IOError:
|
||||
pass
|
||||
|
||||
|
||||
Reference in New Issue
Block a user