vinniyo
vinniyo

Reputation: 877

TCL UTF-8 encoding in ubuntu from http response

Using windows to request http://gdata.youtube.com/feeds/api/videos/idjyusDUGSc?v=2&alt=jsonc returns russian characters. In windows I use:

puts "[encoding convertfrom utf-8 $data]"

to show the response in cp1252... which works fine.

I shouldn't have to convert while using ubuntu because its utf-8 system encoding... or so I thought, but it will not return correctly. Using:

package require http
set token [http::geturl http://gdata.youtube.com/feeds/api/videos/idjyusDUGSc?v=2&alt=jsonc]
set data [http::data $token]
puts $data

returns an incorrect encoding

Upvotes: 0

Views: 1071

Answers (1)

Roman Mishin
Roman Mishin

Reputation: 501

http::meta $token says that the content is already in utf-8. If you http::geturl directly into file channel, the file will be in utf-8:

package require http
set out [open response.txt w]
http::geturl http://gdata.youtube.com/feeds/api/videos/idjyusDUGSc?v=2&alt=jsonc -channel $out
close $out

Tested on Windows XP.

Upvotes: 0

Related Questions