urlread

  • La solution trouvée sur un forum:

Sur le MATLAB central on peut voir par exemple dans ce post
Thread Subject: Using URLREAD on IMDB

qu’il suffit d’éditer urlread.m et y ajouter
urlConnection.setRequestProperty(‘User-Agent’,’Mozilla 5.0′);

Mais bon éditer un code source n’est pas une bonne pratique bien que cette solution fonctionne.

  • La solution TMW:

Ayant remonté ce problème au support technique de tMW, j’ai eu une explication très satisfaisante sur le sujet :

The biggest difference between URLREAD in MATLAB and in standalone mode is the User-Agent which it reports (in MATLAB it returns the User-Agent string of the built-in browser used by the WEB command, in standalone it only returns your JRE version). Possibly the server of the specific URL which is not working does not « like » the User-Agent in standalone mode.

To work around this you can change the User-Agent by setting the http.agent Java property, for example:
java.lang.System.setProperty(‘http.agent’,’Mozilla/5.0′)

On a recompilé notre code avec cette ligne et ça a aussi corrigé le problème.

  • La solution Fex:

Le 21 Mars 2012 Yair avait posté un sujet Expanding urlread capabilities qui pointait vers l’utilitaire urlread2.
Cette solution aussi fonctionne très bien et d’ailleurs je la conseille.
Pour s’en convaincre il suffit de prendre l’url qui est discutée dans le sujet du MATLAB Central : http://www.imdb.com/title/tt0372784/

Voici les différents tests en R2011b:

1er test (urlread normal): Failed

>> str = urlread(‘http://www.imdb.com/title/tt0372784/’)
Error using urlread (line 111)
Error downloading URL. Your network connection may be down or your proxy settings improperly configured.

2ème test (java.lang juste avant): Failed

On aura la même erreur en faisant :
>> java.lang.System.setProperty(‘http.agent’,’Mozilla/5.0′)
>>str = urlread(‘http://www.imdb.com/title/tt0372784/’)
Error using urlread (line 111)
Error downloading URL. Your network connection may be down or your proxy settings improperly configured.

3ème test (urlread.m modifié): OK

En ajoutant la ligne urlConnection.setRequestProperty(‘User-Agent’,’Mozilla 5.0′) dans urlread.m ça marche … mais bon comme je disais pas top de modifier un code source.

4ème test (urlread2 de Jim Hokanson): OK

Alors qu’avec urlread2 , ça marche sans problème!
>> str = urlread2(‘http://www.imdb.com/title/tt0372784/’)
str retourne bien le contenu de la page.

  • bug corrigé

Je reproduis l’erreur « Error downloading URL. Your network connection may be down or your proxy settings improperly configured. » en R2010b , R2011a et R2011b.
En revanche en R2012a et R2012b prerelease urlread fonctionne très bien.
Upgrader est toujours bon!

Laisser un commentaire