Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
817 views
in Technique[技术] by (71.8m points)

python - Pyramid Replacing Double Forward-Slash in URL Matchdict

Essentially, I'm just building an API redirection route inside of Pyramid to process cross-domain AJAX requests without using JSONP.

I've added a route, like so:

config.add_route("api","/api/{url:.*}")

with which I want to capture URLs like so:

http://domain.com/api/http://location.of/other/api

However, when grabbing the captured URL suffix out of the Request matchdict, I get the following:

http:/location.of/other/api

I'm guessing some escaping has been done during URL processing/matching? How can I avoid this, and get the desired URL with two forward slashes?

Even if I pass the URL in as a GET parameter, the issue remains. Perhaps it's something to do with the way Pyramid's multidicts work?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

This is a fundamental limitation of any WSGI-based application. URLs are urldecoded and slashes are compacted before the URL is passed to the WSGI app. If you want to preserve the slashes you will need to urlencode them twice. AFAIK there is no way around this using a query string.

I guess I should point out that the original URL is available, but from it you will have to parse out the part you care about yourself. It is in request.url. request.path_info is what Pyramid and most WSGI apps use to dispatch URLs because it contains only the sub-path that is relative to where the app is mounted.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...