How do I get the current url in web2py? - url

In web2py how do I get the complete url of the current page? I want the (possibly rewritten) url that appears in the browser address bar.
e.g.
http://www.example.com/products/televisions?sort=price&page=2

The easiest method to generate this is probably:
URL(args=request.args, vars=request.get_vars, host=True)
You could also assemble the URL this way:
'%s://%s%s' % (request.env.wsgi_url_scheme, request.env.http_host,
request.env.web2py_original_uri)

I know this is an old thread - this is what it took for me in 2017 to get the original url:
url = '%s://%s%s' % (request.env.wsgi_url_scheme, request.env.http_host,
request.env.request_uri)
Close to the previous answer but the uri was elsewhere.

Related

Inside Splash, how to use src attribute to append to a url

------------ORIGINAL QUESTION------------------
In my Splash Script, I am trying to use "splash:go" on a new url that is based on the "src" attribute of an "img" tag. How can I access this "src" relative url and join it to a start_url?
For example, imagine that the img element has the following contents:
<img id="ImageViewer1_docImage" onload="BlockerResize('ImageViewer1_ContentBlocker1','ImageViewer1_WaterMarkImage');" src="ACSResource.axd?SCTTYPE=ENCRYPTED&SCTKEY=gMYed5OWqcT9I1Y2fM85DvB48X5U1DQ5mOUiJoUH4rioyau0nJdxt0PHFfGVTMiUsork/YD+Cw0F6ZzcviP4sG09xrqWM8/zJlyEeVRFkKXVnkyHYWgwNJzCSUE4Kh4yCsqw6mCuIxWxPj6BAI7Hbw==&CNTWIDTH=849&CNTHEIGHT=684&FITTYPE=Height&ZOOM=1" alt="Please wait" style="border-width:0px;cursor: url(images/Cursors/hmove.cur); z-index: 1000">
Here I am trying to extract the src attribute and add it to start_url:
https://i2a.uslandrecords.com/ME/Cumberland/D/
I want all of this inside the Splash script. I need it to be done inside of Splash because otherwise I lose my security/encryption or something--it renders "Bad Data" instead of the new webpage. Do you have any recommendations?
------------UPDATE------------------
So I managed to obtain the url I needed from the src attribute using the following code:
var = splash:evaljs("document.getElementById('ImageViewer1_docImage').src;")
splash:go(var)
However, the problem is that this is producing a error message. All I find in the snapshot is a white page with the following message:
Failed loading page (Frame load interrupted by policy change)
https://i2a.uslandrecords.com/ME/Cumberland/D/ACSResource.axd?SCTTYPE=ENCRYPTED&SCTKEY=gMYed5OWqcSvEWOJA6wGVmb642s2oZHqkYmT6VTpORTzMY7CgvDU5jsjJG/xp0X3eQ9BiDnbaTdAmISeLkC3hyjxGjcSnXOKgGDa8cI2fniY0ILT+NqvQToMGIB+/X3ZIs7Q+D4ppTSZGYZ2L4M/
Webkit error #102
Any idea why?
The image src attribute is exactly the URL you need to access or as stated by the question title you need to append it to some other URL parts?
If that is the case, you can do it by '..'
Ex.: splash:go(base_url..var) -- concatenation
ISSUE RESOLVED:
Here is the solution. The GET request was breaking down because it didn't know how to render the image in html given the webkit settings. If you execute the GET request without rendering the page, the response.body has the image.
CODE:
local response = splash:http_get(var)
return {
body = response.body
}

how to get fixed static images url for jenkins?

I generated the html webpage in jenkins jobs and try to success/failure icons inside.
But I noticed it is linked to the url with some random number 9b17c509 in the path
https://ci.jenkins.io/static/9b17c509/images/32x32/red.png
What I preferred is the fixed url for every jenkins instance like
https://ci.jenkins.io/static/images/32x32/blue.png
Any suggestion to solve it ?
BTW: I don't want to connect to external web for those images
9b17c509 looks like a cache.
We can use /images/32x32/blue.png
see https://ci.jenkins.io/images/32x32/blue.png
For a hudson.model.Result or the result name like "SUCCESS" you can get a ball icon with hudson.model.BallColor .
In Groovy
def iconUrl = (result as BallColor).getImageOf("16x16")

Current site URL in Liferay 6.2

I cannot figure out how to get URL of current site in Liferay. For example if i have created four sites - site1, site2, site3, site4. URL of this sites will be:
http://localhost:8080/web/site1/
http://localhost:8080/web/site2/
http://localhost:8080/web/site3/
http://localhost:8080/web/site4/
But how can i get this URLs from velocity (in theme)? I tried few options:
$themeDisplay.getPathFriendlyURLPublic() - /web
$themeDisplay.getPortalURL() - http://localhost:8080
$themeDisplay.getURLHome() - http://localhost:8080/web/guest
$themeDisplay.getURLCurrent() - /web/site1/home
I need to get just http://localhost:8080/web/actualsite/.
All right, after few hours of trying I find solution:
To get current site url, you need to use:
$layout.getGroup().friendlyURL in velocity.
This expression returns '/site-name' format.
Try this in your theme vm. This should give you current complete url.
$portalUtil.getCurrentCompleteURL($request)
Output : http://localhost:8080/web/site4/home

Long URL as a command line doesn't work whereas a smaller URL works

I am trying to extract image frames from a video. I am passing the video URL as a command line argument. I am using a long URL as below.
Extract.exe C:\Users\Public\Videos\Sample Videos\Wildlife.wmv
This doesn't work and it calls the help(), maybe because of argument count not being equal to 2. (The argument count shows 3).
When I put a short URL as below,
Extract.exe F:\Wildlife.wmv
It works fine.
What could be the problem with the long URL command line ? How can I overcome this hurdle ?
You have some guidance for me ? Well, I am glad to have it with many thanks !!!
Its because you have spaces in your path name
Extract.exe "C:\Users\Public\Videos\Sample Videos\Wildlife.wmv"
should work.

request.serverVariables() "URL" vs "Script_Name"

I am maintaining a classic asp application and while going over the code I came across two similar lines of code:
Request.ServerVariables("URL")
' Output: "/path/to/file.asp"
Request.ServerVariables("SCRIPT_NAME")
' Output: "/path/to/file.asp"
I don't get it... what is the difference? both of them ignore the URL rewriting that I have set up which puts the /path folder as the root document (the above URL is rewritten to "/to/file.asp")
More info:
The site is deployed on IIS 7
URL Gives the base portion of the URL, without any querystring or extra path information. For the raw URL, use HTTP_URL or UNENCODED_URL.
SCRIPT_NAME A virtual path to the script being executed. Can be used for self-referencing URLs.
See, http://www.requestservervariables.com/url
and /script_name for the definitions.
This could be a bug under IIS 7.
I could not get Request.ServerVariables("URL") and Request.ServerVariables("SCRIPT_NAME") to return different values. I've tried the cases where they were called from an included file (<!--#include file="file.asp"-->) or after a Server.Transfer.
Is this maybe there in case of Server.Transfer?
In the case where you do a server.transfer i think you would get different results
i.e. SCRIPT_NAME would be e.g. /path/to.transferredfile.asp whereas URL would remain as /path/to/file.asp

Resources