Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

HTTP response code: 403 on http://translate.google.com/translate_tts?q=hello%20world

 
axel garcia
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm trying to play the mp3 output from the google translator, but I get an 403.
By replacing google with another site that serves up the mp3, it works.

import java.io.*;
import java.net.*;
import javazoom.jl.player.Player;
public class MP3{
private Player player;
public void close(){if(player!=null)player.close();}
public void play(){
try {
URL myURL = new URL("http://translate.google.com/translate_tts?q=hello%20world");
// myURL = new URL("http://anothersite.com/1.mp3");
BufferedInputStream bis = new BufferedInputStream(myURL.openStream());
player = new Player(bis);
}catch (Exception e){
e.printStackTrace();
}
new Thread(){
public void run(){
try {player.play();}
catch(Exception e){System.out.println(e);}
}
}.start();
}
public static void main(String[] args) {
MP3 mp3 = new MP3();
int N = 4000;
double sum = 0.0;
for(int i = 0;i<N;i++){for(int j = 0;j< N;j++){sum += Math.sin(i + j);}}
System.out.println(sum);
mp3.close();
mp3 = new MP3();
mp3.play();
}
}


java.io.IOException: Server returned HTTP response code: 403 for URL: http://translate.google.com/translate_tts?q=hello%20world
java.lang.NullPointerException
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)
at java.net.URL.openStream(Unknown Source)
at MP3.play(MP3.java:11)
at MP3.main(MP3.java:31)
 
Rob Spoor
Sheriff
Pie
Posts: 20511
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Error 403 is "forbidden". You are not allowed to open this file. The cause may be some missing or incorrect headers. Can you open that MP3 in a regular browser?
 
axel garcia
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rob Prime wrote:Error 403 is "forbidden". You are not allowed to open this file. The cause may be some missing or incorrect headers. Can you open that MP3 in a regular browser?


yes.
 
Rob Spoor
Sheriff
Pie
Posts: 20511
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Then the problem is either caused by headers that are not allowed by Google, or by a proxy you are using with the browser.

For the first you should intercept the headers sent by the browser to Google. You can use the TamperData plugin for Firefox for this. I'm a nice bloke so I did it for you. These are the request headers when sent with Firefox 3.6.3:
For the second, check out java.net.Proxy.

If you still have problems you may want to start using Apache's HttpClient.
 
axel garcia
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks. httpunit works. snippet.

WebConversation webConversation = new WebConversation();
HttpUnitOptions.setScriptingEnabled(false);
WebResponse webResponse = webConversation
.getResponse("http://translate.google.com/translate_tts?q=hello%20world");
BufferedInputStream bis = new BufferedInputStream(webResponse.getInputStream());
 
Rob Spoor
Sheriff
Pie
Posts: 20511
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for sharing the solution
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic