Skip to content

Korean characters are not displayed correctly in Glue notebook.

0

"Glue version information is as follows. The result of the print statement comes out as '??'. How do I solve it??"

%idle_timeout 120
%glue_version 5.0
%worker_type G.1X
%number_of_workers 2
# 추가 라이브러리
%additional_python_modules awswrangler,openpyxl

import boto3
import sys
from awsglue.dynamicframe import DynamicFrame
from awsglue.transforms import *
from awsglue.utils import getResolvedOptions
from pyspark.context import SparkContext
from pyspark.sql.functions import *
from awsglue.context import GlueContext
from awsglue.job import Job

# 사용자 추가 라이브러리 
#import pyspark.pandas as ppd
import awswrangler as wr
import numpy as np

sc = SparkContext.getOrCreate()
glueContext = GlueContext(sc)
spark = glueContext.spark_session
job = Job(glueContext)

print('안녕')

Welcome to the Glue Interactive Sessions Kernel For more information on available magic commands, please type %help in any new cell.

Please view our Getting Started page to access the most up-to-date information on the Interactive Sessions kernel: https://docs.aws.amazon.com/glue/latest/dg/interactive-sessions.html Installed kernel version: 1.0.7 Current idle_timeout is None minutes. idle_timeout has been set to 120 minutes. Setting Glue version to: 5.0 Previous worker type: None Setting new worker type to: G.1X Previous number of workers: None Setting new number of workers to: 2 Additional python modules to be included: awswrangler openpyxl Trying to create a Glue session for the kernel. Session Type: glueetl Worker Type: G.1X Number of Workers: 2 Idle Timeout: 120 Session ID: ed85e92e-6498-4533-a7a4-8dc55219f941 Applying the following default arguments: --glue_kernel_version 1.0.7 --enable-glue-datacatalog true --additional-python-modules awswrangler,openpyxl Waiting for session ed85e92e-6498-4533-a7a4-8dc55219f941 to get into ready status... Session ed85e92e-6498-4533-a7a4-8dc55219f941 has been created. ??

For reference.

aa = '한글'
if aa == '한글':
    print("ok")
    print("오케이")
else:
    print("No")
# ok
# ???

asked 2 years ago141 views

1 Answer
0

The issue you're experiencing with Korean characters not displaying correctly in your AWS Glue notebook is likely related to character encoding. To resolve this problem, you can try the following approaches:

  1. Set the correct encoding when printing: Instead of using a simple print statement, try encoding the string explicitly:

    print('안녕'.encode('utf-8').decode('utf-8'))
  2. Ensure your Glue job's environment is set to use UTF-8: You can set the environment variable PYTHONIOENCODING to UTF-8 at the beginning of your script:

    import os
    os.environ['PYTHONIOENCODING'] = 'UTF-8'
  3. Check your data source encoding: If you're reading data from a file or database, make sure it's encoded in UTF-8. When reading files, you may need to specify the encoding explicitly.

  4. Use Unicode escape sequences: As a workaround, you can use Unicode escape sequences to represent Korean characters:

    print('\uc548\ub155')  # This will print '안녕'
  5. Verify your Glue notebook's character encoding settings: Check if there are any settings in your Glue notebook interface that allow you to specify the character encoding.

If these solutions don't work, the issue might be related to how your Glue environment is configured. In that case, you may need to contact AWS support for further assistance.

Remember to test each solution carefully, as the effectiveness may vary depending on your specific setup and the source of the encoding issue.
Sources
UNICODE - AWS Glue DataBrew
Data Quality for ETL jobs in AWS Glue Studio notebooks - AWS Glue

answered 2 years ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.