Search code examples
python-2.7google-app-enginegclouddev-appserver

How can I fix Google App Engine dev_appserver.py: watcher_ignore_re flag "is not JSON serializable" error?


I wanna first point out that I tried every answers mentioned in this thread. None of these seem to fix the issue and the question already dates a while back.

Issue

I want to run the dev_appserver.py while adding certain files to the ignore list for the watcher; this means that the skip_files is out of the question as this option removes them from being read by the server.

When I run dev_appserver.py without the --watcher_ignore_re flag, everything works fine except for the file watch. When I do run it with the flag, I get the following error:

INFO     2021-11-02 13:54:50,100 devappserver2.py:309] Skipping SDK update check.
Traceback (most recent call last):
  File "/home/USERNAME/google-cloud-sdk/platform/google_appengine/dev_appserver.py", line 109, in <module>
    _run_file(__file__, globals())
  File "/home/USERNAME/google-cloud-sdk/platform/google_appengine/dev_appserver.py", line 103, in _run_file
    _execfile(_PATHS.script_file(script_name), globals_)
  File "/home/USERNAME/google-cloud-sdk/platform/google_appengine/dev_appserver.py", line 83, in _execfile
    execfile(fn, scope)
  File "/home/USERNAME/google-cloud-sdk/platform/google_appengine/google/appengine/tools/devappserver2/devappserver2.py", line 635, in <module>
    main()
  File "/home/USERNAME/google-cloud-sdk/platform/google_appengine/google/appengine/tools/devappserver2/devappserver2.py", line 623, in main
    dev_server.start(options)
  File "/home/USERNAME/google-cloud-sdk/platform/google_appengine/google/appengine/tools/devappserver2/devappserver2.py", line 356, in start
    java_major_version=self.java_major_version
  File "/home/USERNAME/google-cloud-sdk/platform/google_appengine/google/appengine/tools/devappserver2/metrics.py", line 185, in Start
    self._cmd_args = json.dumps(vars(cmd_args)) if cmd_args else None
  File "/usr/lib/python2.7/json/__init__.py", line 244, in dumps
    return _default_encoder.encode(obj)
  File "/usr/lib/python2.7/json/encoder.py", line 207, in encode
    chunks = self.iterencode(o, _one_shot=True)
  File "/usr/lib/python2.7/json/encoder.py", line 270, in iterencode
    return _iterencode(o, 0)
  File "/usr/lib/python2.7/json/encoder.py", line 184, in default
    raise TypeError(repr(o) + " is not JSON serializable")
TypeError: <_sre.SRE_Pattern object at 0x7f720c625240> is not JSON serializable

I have tried with different versions without success:

  • GCloud 361.0.0/362.0.0/357.0.0/240.0.0/220.0.0/200.0.0
  • Python 2.7.18/3.9.7

I have also tried different string values on the watcher flag:

  • ""
  • ''
  • ".css"
  • "*.css"
  • ".*\css"
  • '.css'
  • '*.css'
  • '.*\css'
  • etc.

I know the issue is therefore not with how the string is formulated (at least it doesn't seem like it). And the different version don't help either.

My work colleagues don't have this issue and are using different versions I listed here on MacOS. I am currently on arch Linux, but I have ran into the exact same issue on my mac as well.

I have also added export CLOUDSDK_PYTHON=python2.7 in my ~/.zshrc file.


Solution

  • So turns out this was a duplicate after all. I missed one comment that had the solution. This one: https://stackoverflow.com/a/52238832/9706597

    It looks like it is an issue with the google analytics code built into dev_appserver2 (google-cloud-sdk\platform\google_appengine\google\appengine\tools\devappserver2\devappserver2.py on or around line 316). It wants to send all of your command line options to google analytics. If you remove the analytics client id by adding the command line option --google_analytics_client_id= (note: '=' without any following value) the appserver won't call the google analytics code where it is trying to JSON serialize an SRE object and failing.
    

    In a few short words for anyone else coming through here, simply add this option, simply add this option:

    --google_analytics_client_id= with no value.