[PYTHON] Ich war süchtig nach der Bereitstellung von Google Cloud-Funktionen (der Codec 'ascii' kann das Zeichen u '\ u281b' an Position 58 nicht codieren).

Überblick

Fehlerinhalt

[usr_id@PC_NAME] ~/Documents/project/function_name
% gcloud functions deploy function-name --region asia-northeast1 --runtime python37 --trigger-topic topic-name         #Befehl bereitstellen
Deploying function (may take a while - up to 2 minutes)...failed.                                                                                                                                                                                                         
ERROR: gcloud crashed (UnicodeEncodeError): 'ascii' codec can't encode character u'\u281b' in position 58: ordinal not in range(128)
If you would like to report this issue, please run the following command:
  gcloud feedback
To check gcloud for common problems, please run the following command:
  gcloud info --run-diagnostics
[usr_id@PC_NAME] ~/Documents/project/function_name
% gcloud info --run-diagnostics         #Fehlerdetails
Network diagnostic detects and fixes local network connection issues.
Exception in thread Thread-1:                                                                                                                                                                                                                                             
Traceback (most recent call last):
  File "/Users/usr_id/.pyenv/versions/2.7.0/lib/python2.7/threading.py", line 530, in __bootstrap_inner
    self.run()
  File "/Users/usr_id/.pyenv/versions/2.7.0/lib/python2.7/threading.py", line 483, in run
    self.__target(*self.__args, **self.__kwargs)
  File "/Users/usr_id/google-cloud-sdk/lib/googlecloudsdk/core/console/progress_tracker.py", line 164, in Ticker
    if self.Tick():
  File "/Users/usr_id/google-cloud-sdk/lib/googlecloudsdk/core/console/progress_tracker.py", line 235, in Tick
    self._Print(self._GetSuffix())
  File "/Users/usr_id/google-cloud-sdk/lib/googlecloudsdk/core/console/progress_tracker.py", line 261, in _Print
    self._console_output.UpdateConsole()
  File "/Users/usr_id/google-cloud-sdk/lib/googlecloudsdk/core/console/multiline.py", line 154, in UpdateConsole
    self._UpdateConsole()
  File "/Users/usr_id/google-cloud-sdk/lib/googlecloudsdk/core/console/multiline.py", line 168, in _UpdateConsole
    self._messages[self._last_print_index].Print()
  File "/Users/usr_id/google-cloud-sdk/lib/googlecloudsdk/core/console/multiline.py", line 281, in Print
    self._WriteLine(line)
  File "/Users/usr_id/google-cloud-sdk/lib/googlecloudsdk/core/console/multiline.py", line 331, in _WriteLine
    self._stream.write(self._level * INDENTATION_WIDTH * ' ' + line)
UnicodeEncodeError: 'ascii' codec can't encode character u'\u281b' in position 30: ordinal not in range(128)
Checking network connection...done.                                                                                                                                                                                                                                       
Reachability Check passed.
Network diagnostic passed (1/1 checks passed).
Property diagnostic detects issues that may be caused by properties.
Checking hidden properties...done.                                                                                                                                                                                                                                        
Hidden Property Check passed.
Property diagnostic passed (1/1 checks passed).
gcloud crashed (UnicodeEncodeError): 'ascii' codec can't encode character u'\u281b' in position 58: ordinal not in range(128)

die Einstellungen

--Python wird im SDK verwendet --python2.7 in pyenv setzen

[usr_id@PC_NAME] ~/Documents/project/function-name
% echo $CLOUDSDK_PYTHON
/Users/usr_id/.pyenv/versions/2.7.0/bin/python

Korrespondenz 1

--Versuchen Sie, die Standardkodierung zu ändern --Referenz:

Vor dem Ändern der Standardcodierung

% $CLOUDSDK_PYTHON
Python 2.7 (r27:82500, Nov  1 2019, 14:21:44)
[GCC 4.2.1 Compatible Apple LLVM 10.0.1 (clang-1001.0.46.4)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.getdefaultencoding()
'shift-jis'
>>>

Versuchen Sie, die Standardcodierung zu ändern

[usr_id@PC_NAME] ~/.pyenv/versions/2.7.0/lib/python2.7/site-packages
% pwd
/Users/usr_id/.pyenv/versions/2.7.0/lib/python2.7/site-packages
[usr_id@PC_NAME] ~/.pyenv/versions/2.7.0/lib/python2.7/site-packages
% cat sitecustomize.py
import sys
sys.setdefaultencoding('utf-8')
[usr_id@PC_NAME] ~/.pyenv/versions/2.7.0/lib/python2.7/site-packages
% $CLOUDSDK_PYTHON
Python 2.7 (r27:82500, Nov  1 2019, 14:21:44)
[GCC 4.2.1 Compatible Apple LLVM 10.0.1 (clang-1001.0.46.4)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.getdefaultencoding()
'utf-8'
>>>

Korrespondenz 2

Versuche zu ändern

[usr_id@PC_NAME] /Library/Python/2.7/site-packages
% echo $CLOUDSDK_PYTHON
/usr/bin/python2.7
[usr_id@PC_NAME] /Library/Python/2.7/site-packages
% pwd
/Library/Python/2.7/site-packages
[usr_id@PC_NAME] /Library/Python/2.7/site-packages
% $CLOUDSDK_PYTHON
Python 2.7.16 (default, Oct 16 2019, 00:34:56)
[GCC 4.2.1 Compatible Apple LLVM 10.0.1 (clang-1001.0.37.14)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.getdefaultencoding()
'utf-8'
>>>

»Das hat es gelöst!

[usr_id@PC_NAME] ~/Documents/project/function-name
% gcloud functions deploy function-name --region asia-northeast1 --runtime python37 --trigger-topic topicname
Deploying function (may take a while - up to 2 minutes)...done.                                                                                                                                       
availableMemoryMb: 256
entryPoint: function-name
eventTrigger:
  eventType: google.pubsub.topic.publish
  failurePolicy: {}
  resource: projects/project-name/topics/topicname
  service: pubsub.googleapis.com
ingressSettings: ALLOW_ALL
labels:
  deployment-tool: cli-gcloud
name: projects/project-name/locations/asia-northeast1/functions/function-name
runtime: python37
serviceAccountEmail: [email protected]
sourceUploadUrl: hogehoge
status: ACTIVE
timeout: 60s
updateTime: '2020-02-06T02:15:16Z'
versionId: '19'

Ursache (Einbildung)

Bemerkungen

Recommended Posts

Ich war süchtig nach der Bereitstellung von Google Cloud-Funktionen (der Codec 'ascii' kann das Zeichen u '\ u281b' an Position 58 nicht codieren).
Der Codec 'shift_jis' kann das Zeichen '\ uff0d' an Position 0 nicht codieren: Unzulässige Multibyte-Sequenz auflösen
Ich war süchtig danach, 2020 mit Selen (+ Python) zu kratzen
Ich war süchtig danach, logging.getLogger mit Flask 1.1.x zu versuchen
Der Codec 'Ascii' kann keine Zeichen an Position xx-xx codieren: Ordnungszahl nicht im Bereich (128), wenn PHP → Python aufgerufen wird
Was ich mit json.dumps in Pythons base64-Codierung süchtig gemacht habe
Ich war süchtig nach falschen Klassenvariablen und Instanzvariablen in Python
Ich war süchtig nach Multiprocessing + Psycopg2
Der Dateiname war in Python schlecht und ich war süchtig nach Import
Ich war süchtig danach, mysqlclient zu installieren
Ich war auf dotCloud süchtig nach Flask
Was ich süchtig nach Python Autorun war