1

According to the docs on App Engine, when using the appspot.com domain you have to do some trickery with -dot- instead of . in subdomains.

Please note that in April of 2013, Google stopped issuing SSL certificates for double-wildcard domains hosted at appspot.com (i.e. ..appspot.com). If you rely on such URLs for HTTPS access to your application, please change any application logic to use "-dot-" instead of ".". For example, to access version "1" of application "myapp" use "https://1-dot-myapp.appspot.com" instead of "https://1.myapp.appspot.com." If you continue to use "https://1.myapp.appspot.com" the certificate will not match, which will result in an error for any User-Agent that expects the URL and certificate to match exactly.

I am trying to figure out the best way to generate these URLs using the SDK without manually replacing the dots. I've tried modules.get_hostname(module="my module name") but it returns a traditional sub-domain that triggers the SSL mismatch error.

Edit Per suggestion, I opened a feature request for this functionality

Josh J
  • 6,813
  • 3
  • 25
  • 47

2 Answers2

2

So given for example

x = 'https://1.amodule.myapp.appspot.com'

you need to replace all but the last two dots with -dot- (the last two must remain since the .appspot.com part much stay untouched).

Given this, I'd recommend:

>>> x = 'https://1.amodule.myapp.appspot.com'
>>> dots = x.count('.')
>>> x.replace('.', '-dot-', dots - 2)
'https://1-dot-amodule-dot-myapp.appspot.com'

The key ideas: x.count('.') tells you how many dots in all string x contains; the third optional argument to x.replace tells Python how many dots, at most, are to be replaced.

Alex Martelli
  • 854,459
  • 170
  • 1,222
  • 1,395
  • "without manually replacing the dots". Your solution is my last ditch effort. I'm looking for an SDK built-in way. – Josh J Mar 10 '15 at 11:17
  • @Trii, the SDK does not offer this two-line function (I don't see what's "manual" about it -- it's fully automated!). Feel free to open a feature request at https://code.google.com/p/googleappengine/issues/list . – Alex Martelli Mar 10 '15 at 14:30
  • 1
    By "manual" I mean not part of the SDK proper so if they change behavior in the future, I will also need to update my code. Manual was a poor choice of words. In the old appengine web console under versions, some of the version links will route to the `-dot-` formatted hostnames so I thought their must be something in the SDK that is smart enough to figure it out. If that is not the case, then the answer to my question is "No, there is no SDK way" and I'll go open a feature request. Thank you for your detail though, the answer is helpful for others even though it does not answer my question. – Josh J Mar 10 '15 at 16:08
0

The gcloud command-line utility now has gcloud app browse, which will take you to the correct URL. For example, the following commands will launch the URL https://1-dot-amodule-dot-myapp.appspot.com:

gcloud config set project myapp
gcloud app browse --service="amodule" --version="1"

Or

gcloud app browse --project="myapp" --service="amodule" --version="1"

By default it will attempt opening the URL in a browser, but you can use the --no-launch-browser flag to only display the URL.

Full docs at https://cloud.google.com/sdk/gcloud/reference/app/browse.

Chris Calo
  • 7,518
  • 7
  • 48
  • 64