Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Encoding varsayılan olarak UTF8 ayarlanmalı #39

Closed
msdundar opened this issue Sep 28, 2018 · 3 comments
Closed

Encoding varsayılan olarak UTF8 ayarlanmalı #39

msdundar opened this issue Sep 28, 2018 · 3 comments

Comments

@msdundar
Copy link
Contributor

msdundar commented Sep 28, 2018

Açıklama

Xokul'dan dönen yanıtlar #<Encoding:ASCII-8BIT> olarak encode edilmiş görünüyor:

response.body.encoding
#<Encoding:ASCII-8BIT>

Dönen yanıt örneği:

response_body = "{\"id_number\":14674478966,\"blue_card_informations\":null,\"citizenship_informations\":{\"temporary_identity_informations\":null,\"personal_informations\":{\"id_number\":14674478966,\"old_id_number\":null,\"fathers_id_number\":null,\"mothers_id_number\":null,\"code_of_place_of_birth\":1447,\"basic_informations\":{\"first_name\":\"Mustafa Serhat\",\"last_name\":\"D\xC3\xBCndar\",\"fathers_name\":\"Erhan\",\"mothers_name\":\"Fatma\",\"gender\":{\"code\":1,\"description\":\"Erkek\"},\"place_of_birth\":\"Kars\",\"date_of_birth\":\"1990-09-08\"},\"status_informations\":{\"religion\":null,\"status\":{\"code\":1,\"description\":\"A\xC3\xA7\xC4\xB1k\"},\"marital_status\":{\"code\":2,\"description\":\"Evli\"},\"date_of_death\":null},\"place_of_registry\":{\"family_serial_number\":158,\"individual_serial_number\":48,\"volume\":{\"code\":5,\"description\":\"Hac\xC4\xB1yahya\"},\"city\":{\"code\":5,\"description\":\"Amasya\"},\"district\":{\"code\":1368,\"description\":\"G\xC3\xBCm\xC3\xBC\xC5\x9Fhac\xC4\xB1k\xC3\xB6y\"}}},\"old_identity_card_informations\":null,\"new_identity_card_informations\":{\"id_number\":null,\"first_name\":\"Mustafa Serhat\",\"last_name\":\"D\xC3\xBCndar\",\"fathers_name\":\"Erhan\",\"mothers_name\":\"Fatma\",\"gender\":{\"code\":1,\"description\":\"Erkek\"},\"place_of_birth\":\"Kars\",\"date_of_birth\":\"1990-09-08\",\"registry_number\":17480994,\"serial_number\":0,\"date_of_expiration\":\"2027-05-10\",\"admission_reason\":{\"code\":2,\"description\":\"De\xC4\x9Fi\xC5\x9Ftirme\"},\"deliverer_unit\":null,\"date_of_delivery\":\"2017-06-08\",\"issuing_authority\":\"T.C. \xC4\xB0\xC3\xA7i\xC5\x9Fleri Bakanl\xC4\xB1\xC4\x9F\xC4\xB1\",\"photograph\":null}},\"foreigner_informations\":null}"

Gelen response'a to_json dediğimde hata alıyorum:

Encoding::UndefinedConversionError: "\xC3" from ASCII-8BIT to UTF-8

Ancak force_encoding yapabiliyorum:

response.body.force_encoding('utf-8')
"{\"id_number\":14674478966,\"blue_card_informations\":null,\"citizenship_informations\":{\"temporary_identity_informations\":null,\"personal_informations\":{\"id_number\":14674478966,\"old_id_number\":null,\"fathers_id_number\":null,\"mothers_id_number\":null,\"code_of_place_of_birth\":1447,\"basic_informations\":{\"first_name\":\"Mustafa Serhat\",\"last_name\":\"Dündar\",\"fathers_name\":\"Erhan\",\"mothers_name\":\"Fatma\",\"gender\":{\"code\":1,\"description\":\"Erkek\"},\"place_of_birth\":\"Kars\",\"date_of_birth\":\"1990-09-08\"},\"status_informations\":{\"religion\":null,\"status\":{\"code\":1,\"description\":\"Açık\"},\"marital_status\":{\"code\":2,\"description\":\"Evli\"},\"date_of_death\":null},\"place_of_registry\":{\"family_serial_number\":158,\"individual_serial_number\":48,\"volume\":{\"code\":5,\"description\":\"Hacıyahya\"},\"city\":{\"code\":5,\"description\":\"Amasya\"},\"district\":{\"code\":1368,\"description\":\"Gümüşhacıköy\"}}},\"old_identity_card_informations\":null,\"new_identity_card_informations\":{\"id_number\":null,\"first_name\":\"Mustafa Serhat\",\"last_name\":\"Dündar\",\"fathers_name\":\"Erhan\",\"mothers_name\":\"Fatma\",\"gender\":{\"code\":1,\"description\":\"Erkek\"},\"place_of_birth\":\"Kars\",\"date_of_birth\":\"1990-09-08\",\"registry_number\":17480994,\"serial_number\":0,\"date_of_expiration\":\"2027-05-10\",\"admission_reason\":{\"code\":2,\"description\":\"Değiştirme\"},\"deliverer_unit\":null,\"date_of_delivery\":\"2017-06-08\",\"issuing_authority\":\"T.C. İçişleri Bakanlığı\",\"photograph\":null}},\"foreigner_informations\":null}"

Beklenen davranış

Varsayılan olarak UTF8 gelmesi.

@msdundar msdundar added the bug label Sep 28, 2018
@huseyin
Copy link
Contributor

huseyin commented Sep 28, 2018

@msdundar bu daha çok client bağlamında bir sorun gibi görünüyor. Response:

Content-Type: application/json; charset=utf-8
Transfer-Encoding: chunked
Connection: keep-alive
Server: nginx
Date: Fri, 28 Sep 2018 18:39:34 GMT
Vary: Accept-Encoding
ETag: W/"5903774ad458de37306812b18dbbf584"
Cache-Control: max-age=0, private, must-revalidate
X-Request-Id: 7c97825c-759f-4f14-bb86-96f6cc150353
X-Runtime: 1.897954
X-Kong-Upstream-Latency: 1901
X-Kong-Proxy-Latency: 0
Via: kong/0.14.1

Ayrıca diğer istemcilerle sorun yaşamıyorum. Faraday default adaptörü net/http. Yine de soruna bu eksende bir bakacağım.

@huseyin
Copy link
Contributor

huseyin commented Sep 28, 2018

Bir de response zaten JSON formatında. to_json onu yeniden JSON olarak formatlamak anlamına geliyor. Faraday'ın imkanlarına bakmak lazım ama JSON parse generic olarak şöyle:

require 'json'

JSON.parse(json_data)

@huseyin
Copy link
Contributor

huseyin commented Sep 30, 2018

@msdundar bunun client-side bir sorun olduğuna eminiz. diğer dillerle ve GitHub API ile test ettiğimde de encoding "ASCII-8BIT" dönüyor. bu yüzden iş kaydını kapatıyorum

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants