appconfig.ini don't support multi byte character

Open Beginner friendly
#2,310 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
68/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Stale
Tech stack
python
Domain
backend

Research direction

Start in gluon/contrib/appconfig.py at read_config_ini and reproduce the issue with Japanese or another multibyte value in appconfig.ini, such as the name or author in the [app] section. Verify the change by opening a controller and confirming the configuration loads without UnicodeDecodeError.

Written by the indexing model from the issue text.

Description

Describe the bug
appconfig.ini don't support multi byte character.

Environment
2.19.1-stable+timestamp.2020.03.21.21.49.28
(Running on nginx/1.14.0, Python 3.6.9)

To Reproduce
Steps to reproduce the behavior:

  1. Use multi byte character in appconfig.ini. (ex. name or author in [app] section)
  2. Open any controller
  3. See error in the ticket
    <class 'UnicodeDecodeError'> 'ascii' codec can't decode byte 0xe3 in position 40: ordinal not in range(128)

Expected behavior

The current read_config_ini function in gluon/contrib/appconfig.py is like followings (around line 125).

def read_config_ini(self):
        config = configparser.SafeConfigParser()
        config.read(self.file)
        settings = {}
        for section in config.sections():

config.read(self.file) should be as follows.

def read_config_ini(self):
        config = configparser.SafeConfigParser()
        config.readfp(codecs.open(self.file, "r", "utf8"))
        settings = {}
        for section in config.sections():

import codecs
is required in the head of gluon/contrib/appconfig.py.

I have confirmed to use Japanese string in appconfig.ini.

Dominant language
Python
Stars
2.2k
Forks
916
Avg merge
2d 4h
Merged PRs (30d)
8

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from web2py/web2py

All issues in web2py/web2py

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.