"regex invalid: unbalanced parenthesis", is it a bug or something?

908 views
Skip to first unread message

satoru

unread,
Apr 8, 2008, 8:12:40 AM4/8/08
to Google App Engine
hi, all.

i got the 'regex invalid: unbalanced parenthesis' error when i tried
to add the following snippet in my 'helloworld\app.yaml'(yes, you
guess it, i was reading the "Getting Started"s).:

" - url: /stylesheets
static_dir: stylesheets"

i think the reason is that i was running App Engine under windows.
but i don't know exactly why this happen.

Andrey Fedorov

unread,
Apr 8, 2008, 8:31:39 AM4/8/08
to Google App Engine
Ditto - WinXP with Python 2.5.1

shabda raaj

unread,
Apr 8, 2008, 8:40:16 AM4/8/08
to Google App Engine
Can you paste the whole yaml? I guess I have walked through the whole
"Getting Started", but did not face this problem.

Andrey Fedorov

unread,
Apr 8, 2008, 8:50:41 AM4/8/08
to Google App Engine
I'm afraid mine is straight from the website:

--- begin paste ---
application: helloworld
version: 1
runtime: python
api_version: 1

handlers:
- url: /stylesheets
static_dir: stylesheets

- url: /.*
script: helloworld.py
--- end paste ---

Taking out the three lines below "handlers:" fixes the issue.

- Andrey

Andrey Fedorov

unread,
Apr 8, 2008, 8:51:31 AM4/8/08
to Google App Engine
Here is the trace:

Traceback (most recent call last):
File "/cygdrive/c/Program Files/Google/google_appengine/google/
appengine/tools/dev_appserver.py", line 2229, in _HandleRequest
File "/cygdrive/c/Program Files/Google/google_appengine/google/
appengine/tools/dev_appserver.py", line 2409, in LoadAppConfig
File "/cygdrive/c/Program Files/Google/google_appengine/google/
appengine/tools/dev_appserver.py", line 2375, in
CreateURLMatcherFromMaps
File "/cygdrive/c/Program Files/Google/google_appengine/google/
appengine/tools/dev_appserver.py", line 224, in AddURL
InvalidAppConfigError: regex invalid: unbalanced parenthesis

Andrey Fedorov

unread,
Apr 8, 2008, 9:07:10 AM4/8/08
to Google App Engine
I first (foolishly, I guess) ran dev_appserver.py via cygwin, and it
seems my installation keeps referring to /cygdrive/c/..., even though
I'm now running it from Windows. Could this be the problem?

- Andrey

satoru

unread,
Apr 8, 2008, 9:17:56 AM4/8/08
to Google App Engine
i have done several experiment on my machine( winXP with python
2.5.1):
1.my yaml file is just a copy from the tutorial and i guess i can just
put it away and think about other things that may matter
2. the exception is raise in google\appengine\tools\dev_appserver.py
at line 224:

"adjusted_regex = '^%s$' % regex

print repr(adjusted_regex)#

try:
url_re = re.compile(adjusted_regex)
except re.error, e:
raise InvalidAppConfigError, 'regex invalid: %s' % e"
3.at line 2372 in the same file:
"
if handler_type == appinfo.STATIC_DIR:
regex = os.path.join(re.escape(regex), '(.*)')
#regex =
re.escape(os.path.sep).join([re.escape(regex),'(.*)']) #my code
path = os.path.join(path, '\\1')

url_matcher.AddURL(regex,
dispatcher,
path,
requires_login, admin_only)
"
in our case, the handler_type happened to be appinfo.STATIC_DIR,
thus the suite following if excuted.
and repr(regex) is
''\\/stylesheets\\(.*)''.
note that there are 2 backslashes before (.*) and i think that's the
key point the this problem, because it was a multi-role symbol in this
case-- windows path separator, regular expression escaper, normal
string escaper
4.then i changed the statement to :
regex =
re.escape(os.path.sep).join([re.escape(regex),'(.*)']) #my code
and the error didn't pop up again, however, i still cannot see any
css effect.

Please help me solve this problem, thx in advance.

alper...@gmail.com

unread,
Apr 8, 2008, 9:21:17 AM4/8/08
to Google App Engine
Hi,

I have the same problem. I also changed the yaml file to get my image
files as :

- url: /images
static_dir: static/images

described in configuringapp document, but I got the same error :


ERROR 2008-04-08 16:17:37,046 dev_appserver.py] Exception
encountered handlin
g request
Traceback (most recent call last):
File "C:\Program Files\Google\google_appengine\google\appengine\tools
\dev_apps
erver.py", line 2229, in _HandleRequest
config, explicit_matcher = LoadAppConfig(root_path,
self.module_dict)
File "C:\Program Files\Google\google_appengine\google\appengine\tools
\dev_apps
erver.py", line 2409, in LoadAppConfig
module_dict)
File "C:\Program Files\Google\google_appengine\google\appengine\tools
\dev_apps
erver.py", line 2375, in CreateURLMatcherFromMaps
requires_login, admin_only)
File "C:\Program Files\Google\google_appengine\google\appengine\tools
\dev_apps
erver.py", line 224, in AddURL
raise InvalidAppConfigError, 'regex invalid: %s' % e
InvalidAppConfigError: regex invalid: unbalanced parenthesis

Is there any solution?

thanks.

Alper.

Andrey Fedorov

unread,
Apr 8, 2008, 9:39:36 AM4/8/08
to Google App Engine
It seems to be the static_dir attribute name which is triggering it.

Andrey Fedorov

unread,
Apr 8, 2008, 9:43:42 AM4/8/08
to Google App Engine
Looking through the source, it definitely seems like a bug. It's a
"preview release", after all :) I wonder why they didn't call it
"beta".

- Andrey

satoru

unread,
Apr 8, 2008, 10:24:24 AM4/8/08
to Google App Engine
i think it is the url pattern that triggered the exception.
after all, it was used as a regular pattern.
i commented out
""""regex = os.path.join(re.escape(regex), '(.*)')""""
and typed my own statement in:
"""
#regex = os.path.join(re.escape(regex), '(.*)') #original
print 'Before: regex=%s is mapped to path=%s' % (regex,path)
#TESTING
regex = '/'.join([regex,'(.*)'])#TESTING
#path = os.path.join(path, '\\1') #original
path = os.path.sep.join([path, '\\1']) #TESTING
print 'AFTER: regex=%s is mapped to path=%s' % (regex,path)
#TESTING
"""

result:
"""
F:\>dev_appserver.py helloworld
Before: regex=/stylesheets is mapped to path=stylesheets
AFTER: regex=/stylesheets/(.*) is mapped to path=stylesheets\\1
'^/stylesheets/(.*)$'
'^/.*$'
INFO 2008-04-08 22:16:56,328 appcfg.py] Checking for updates to
the SDK.
INFO 2008-04-08 22:16:57,467 appcfg.py] The SDK is up to date.
INFO 2008-04-08 22:16:57,483 dev_appserver_main.py] Running
application hell
oworld on port 8080: http://localhost:8080
"""


this time the url map feature is fixed, however, i still got error
when the page link to the style file:
"""
ERROR 2008-04-08 22:17:45,483 dev_appserver.py] Error encountered
reading fil
e "F:\helloworld\stylesheets\1":
[Errno 2] No such file or directory: 'F:\\helloworld\\stylesheets\\1'
INFO 2008-04-08 22:17:45,500 dev_appserver.py] "GET /stylesheets/
main.css HT
TP/1.1" 404 -
"""
the '\\1' is absolutely regex, however, i haven't figure out what
appengine do to this path afterwards yet.
> > > Please help me solve this problem, thx in advance.- Hide quoted text -
>
> - Show quoted text -

peter.vk

unread,
Apr 8, 2008, 11:15:21 AM4/8/08
to Google App Engine
I don't have a full account yet, but I was working through the
tutorial and am experiencing this same problem.

Anyone find a work around for this yet?

Kind of stupid to have the official tutorial not work.

I have activestate python 2.5.1 installed ans downloaded the zip
version of the SDK.

--
Peter

ma...@google.com

unread,
Apr 8, 2008, 11:37:44 AM4/8/08
to Google App Engine
Thanks for reporting this issue, the above posters have pinpointed the
problem, this is an issue with the static_dir handler regex. I've
filed it in our issue tracker:
http://code.google.com/p/googleappengine/issues/detail?id=20

In the meantime, as a poster on a previous thread pointed out, you can
use the static_files handler as such:
- url: /stylesheets/main.css
static_files: stylesheets/main.css
upload: stylesheets/main.css

Also, you will be able to use the static_dir handler when uploading
your app to Google App Engine, or with the SDK and most Mac and Linux
systems.

-Marzia

peter.vk

unread,
Apr 8, 2008, 11:49:43 AM4/8/08
to Google App Engine
The workaround of filling out the whole url to the static file works
for me. Not really flexible at all (kind of ruins the idea of using
regexps) but it does work.

Any word when an updated SDK will be released?

--
Peter

John Griffiths

unread,
Apr 8, 2008, 12:05:34 PM4/8/08
to Google App Engine
I'd just like to add my voice to those that have found this error. The
workaround posted by Marzia works for me aswell though (XP, Python
2.5.1)

Cheers,
John

On Apr 8, 4:49 pm, "peter.vk" <peter...@gmail.com> wrote:
> The workaround of filling out the whole url to the static file works
> for me. Not really flexible at all (kind of ruins the idea of using
> regexps) but it does work.
>
> Any word when an updated SDK will be released?
>
> --
> Peter
>
> On Apr 8, 11:37 am, ma...@google.com wrote:
>
> > Thanks for reporting this issue, the above posters have pinpointed the
> > problem, this is an issue with thestatic_dirhandler regex. I've
> > filed it in our issue tracker:http://code.google.com/p/googleappengine/issues/detail?id=20
>
> > In the meantime, as a poster on a previous thread pointed out, you can
> > use the static_files handler as such:
> > - url: /stylesheets/main.css
> > static_files: stylesheets/main.css
> > upload: stylesheets/main.css
>
> > Also, you will be able to use thestatic_dirhandler when uploading
> > > > > It seems to be thestatic_dirattribute name which is triggering it.

Andrey Fedorov

unread,
Apr 8, 2008, 12:48:15 PM4/8/08
to Google App Engine
Just got a chance to look... changing the exception thrown on
dev_appserver.py:244 to:

raise InvalidAppConfigError, 'regex "%s" is invalid: %s' %
(adjusted_regex, e)

Throws:

regex "^\/stylesheets\(.*)$" invalid: unbalanced parenthesis

That ( shouldn't be escaped. If we backtrack to dev_appserver:2369, we
see the source of the problem:

regex = os.path.join(re.escape(regex), '(.*)')

I'm not sure exactly why this line uses os.path.join... I'm under the
impression that regex is matched against URL's, not file paths. On
Linux or OSX, the path separator is a forward slash, so there is no
problem, but Windows runs into trouble. Changing line 2369 to

regex = re.escape(regex) + '/(.*)'

Fixes the exception. There's still something broken with how the path
variable works - because of those damned slashes, '\1' is an absolute
path on Windows (os.path.isabs('\\1') == True), but not on Linux or
OSX, and so os.path.join on line 2370 acts differently:

From: http://docs.python.org/lib/module-os.path.html : os.path.join
"joins one or more path components intelligently. If any component is
an absolute path, all previous components (on Windows, including the
previous drive letter, if there was one) are thrown away, and joining
continues..."

I've got to run to class, but will look into a fix later tonight if
nobody figures it out by then. We're getting close!

Cheers,
Andrey

On Apr 8, 11:37 am, ma...@google.com wrote:

Bob L

unread,
Apr 8, 2008, 3:18:26 PM4/8/08
to Google App Engine

It's working for me with this syntax. The '/' at the end stylesheets
got rid of the unbalanced paren issue but then it was looking in the
main application folder for main.css. After adding the '.' everything
appears OK.


application: helloworld
version: 1
runtime: python
api_version: 1

handlers:
- url: /stylesheets./
static_dir: /stylesheets/

ruds

unread,
Apr 8, 2008, 3:47:19 PM4/8/08
to Google App Engine
I had the same problem, then i used Bob L suggestion and i can confirm
it also.
it works fine for me now :D

Ray

unread,
Apr 8, 2008, 5:32:19 PM4/8/08
to Google App Engine
i have my app.yaml set to

application: helloworld
version: 1
runtime: python
api_version: 1

handlers:
- url: /stylesheets./
static_dir: /stylesheets/

- url: /.*
script: helloworld.py



and my index.html is call

<head>
<link type="text/css" rel="stylesheet" href="stylesheets/
main.css" />
</head>



the error message in the console says

INFO 2008-04-08 17:31:04,486 dev_appserver.py] "GET / HTTP/1.1"
200 -
INFO 2008-04-08 17:31:04,517 dev_appserver.py] "GET /stylesheets/
main.css HTTP/1.1" 404 -

any idea what's up ?

Ray

unread,
Apr 8, 2008, 5:43:31 PM4/8/08
to Google App Engine
here's a good fix for windows user

Windows users can use this workaround:

Change lines 2369-70 in <installdir>\google\appengine\tools
\dev_appserver.py from:

regex = os.path.join(re.escape(regex), '(.*)')
path = os.path.join(path, '\\1')

to:

regex = re.escape(regex) + '/(.*)'
path = path + '/\\1'


PS: careful with the indentation.

Bob L

unread,
Apr 8, 2008, 5:49:51 PM4/8/08
to Google App Engine
They're informational messages, not errors. Looks like it's working as
it should.

On Apr 8, 5:32 pm, Ray <yargn...@gmail.com> wrote:

samdc

unread,
Apr 8, 2008, 6:04:16 PM4/8/08
to Google App Engine
Same issue here, using WinXP and Python 2.5.2.

Mine works now with this app.yaml as posted earlier:

application: helloworld
version: 1
runtime: python
api_version: 1

handlers:
- url: /stylesheets/main.css
static_files: stylesheets/main.css
upload: stylesheets/main.css

- url: /.*
script: helloworld.py

When will new SDK come out?

Andrew Burton

unread,
Apr 11, 2008, 1:21:56 AM4/11/08
to Google App Engine
> Windows users can use this workaround:

Go, Ray! Go, Ray! It's your birthday! It's your bithday!

-Andy

asisin

unread,
Apr 12, 2008, 2:40:23 PM4/12/08
to Google App Engine
This is a ridiculous bug rendering the entire thing unusable! You
can't seriously expect me to add an entry for every image, css and
jscript file that my html is loading.

I tried ray's fix, and all the others but only adding a handler entry
for every single file works :-\

Heres my yaml:
application: myapp
version: 1
runtime: python
api_version: 1

handlers:
- url: /
script: home.py

- url: /images/
static_dir: /images

- url: /_css/
static_dir: /_css/

Josh Flanagan

unread,
Apr 12, 2008, 5:18:37 PM4/12/08
to google-a...@googlegroups.com
You don't need to specify every file. This is the workaround that I
used (credit goes to someone else that posted on this group):

- url: /stylesheets/(.*)
static_files: stylesheets/\1
upload: stylesheets/(.*)


Obviously you substitute your folder name for "stylesheets"

Niraj Juneja

unread,
Apr 12, 2008, 8:13:30 PM4/12/08
to Google App Engine
Does not work for me. I am on Vista and Python 2.5

my yaml

application: helloworld
version: 1
runtime: python
api_version: 1
- url: /stylesheets/main.css
static_files: stylesheets/main.css
upload: stylesheets/main.css

- url: /.*
script: helloworld.py


The error I get

C:\XXX\AppEngine>C:\Software\Google\google_appengine\dev_appserver.py
--clear_datastore helloworld/
ERROR 2008-04-12 17:11:18,280 dev_appserver_main.py] Fatal error
when loading application configuration:

Josh Flanagan

unread,
Apr 12, 2008, 8:39:07 PM4/12/08
to google-a...@googlegroups.com
You forgot to start the handlers section...

....
api_version: 1

handlers:
- url: /stylesheets/main.css
...

JvC

unread,
Apr 14, 2008, 4:02:41 PM4/14/08
to Google App Engine
I just solved my problem on windows by changing dev_appserver.py:2369
to:

#regex = os.path.join(re.escape(regex), '(.*)')
regex = regex + '/(.*)'
#path = os.path.join(path, '\\1')
path = path + '/\\1'

my yaml is:
handlers:
- url: /css
static_dir: css
- url: /.*
script: testing.py

now appengine resolves the regexp like this:
/css/(.*) css/\1
/.* testing.py

with \1 being the result of (.*) after /css/

-JvC

Adam

unread,
Apr 18, 2008, 3:09:06 PM4/18/08
to Google App Engine
I was having this same problem on WinXP. The new version [1.01] of
GAE seems to have fixed it.

asimrafi

unread,
Apr 21, 2008, 8:00:57 AM4/21/08
to Google App Engine
It seems working when I have use this.

handlers:
- url: /stylesheets/
static_dir: stylesheets/
Reply all
Reply to author
Forward
0 new messages