Get Redirected URL

I have a bunch of URLs and have discovered they are all Redirects. I need to get the final, target, redirected URL.

Looking at this:

Looks like the solution here is to “Add column based on” original URL. Set the language to Python/Jython. Then this in the Expression box:

import urllib2
response = urllib2.urlopen(value)
return response.geturl()

However, when I do that it results in error:

Error: TypeError: cannot make memory view because object does not have the buffer interface

Any suggestions on how to remedy?

Searching…

Thanks,

Mark

Hi @mcyzyk .

I’ve just tried this locally with one of your URLs and it works for me - which isn’t incredibly helpful I know, but it does mean that this approach can work.

Perhaps the starting point is to try what I did to see if this works for you:

  1. In OpenRefine choose “Create project” and “Get data from” → Clipboard
  2. Type in one of your URLs by hand to avoid there being any underlying issues with how the URL is entered (e.g. encoding).
  3. Click next - you should get a ‘Configure parsing options’ screen with one column containing the URL
  4. Click ‘create project’
  5. Now do the “add colum based on “ step, exactly as above

If you see the expected redirected URL in the preview, then we know it works for you, and likely the issue is something about the data being fed into the process. If it doesn’t work it’s likely that there is some difference between your OpenRefine / Java / Jython setup and mine - so please share :

  • What version of OpenRefine
  • What OS you are on
  • What version of Jython is in use (you can obtain this by starting a transformation with Jython and entering
import sys 
return sys.version_info

Thanks so much, Owen,

I tried that Clipboard test, and No Joy. Same error. Thinking….

OS: Ubuntu 24.04.3 LTS
OpenRefine: 3.8.2
Jython: [ 2, 7, 3, "final", 0 ]

Am I missing a Jython library, maybe?

Mark

Thanks @mcyzyk .

I’m on OpenRefine 3.9.3 and Jython 2.7.4 - so I’d suggest trying updating OpenRefine as a first step, and re-trying (and also re-checking the Jython verison - I’m not sure if that’s independent of the OR version or linked)

If that doesn’t work I’ve got some other possible options if that doesn’t help but I’m less sure about them - so I’d suggest starting with getting the latest version of OR to see if that helps

That worked!

Thank you SO much.

Spinning in chair,

Mark

1 Like

Am I missing a Jython library, maybe?

(and also re-checking the Jython verison - I’m not sure if that’s independent of the OR version or linked)

OpenRefine bundles all necessary Jython components and the bundled version of Jython is fixed for any given OpenRefine release. Jython 2.7.4 was introduced in August 2024 (whatever OpenRefine release came after that date).

Tom

1 Like