Incompatible character encodings ibm866 and windows 1251 vagrant

Incompatible character encodings: UTF-8 and IBM866 (Encod ing::CompatibilityError)

Всем привет. Приступил к изучению Ruby, сразу предупреждаю я абсолютный 0. к программированию вообще никакого отношения не имел.

Начал изучать по книге Криса Пайна «Учись программировать» и. попал в ситуации которые не описаны в учебнике, ситуации кодировкой. С первой проблемой я справился сохранив файл в кодировке UTF-8

это решение не помогло при следующих задачах приведенных в учебнике. Вот что пишет комп:

calc.rb:3:in ` ‘: incompatible character encodings: UTF-8 and IBM866 (Encod
ing::CompatibilityError)

помогите с этим справится..

[C++ Warning] Unit1.cpp(270): W8098 Multi-character character constant
//транслит String translit(String tb) < for(int i=1; i 9

а вообще руби не самый лучший вариант для первого языка

а вообще руби не самый лучший вариант для первого языка

это не помогло

Добавлено через 15 минут
странно что первая часть кода:

работает нормально и отображается,

так же работает и

Добавлено через 4 минуты
это

это не работает

Это только мое имхо, но начинать программную жизнь с ОО языка не есть хорошо. В руби много «магии» для новичка, а если уйти в рор то может сложится впечатление, что это делал Гендальф. Начинать стоит с pure C, пройти через С++, потом желательно через фп язык (lisp или haskel) и уж тогда на руби. Но это только идеал, писающий радугой и отрыгивающий бабочками.

ТС, я даже не подумал что у вас шиндовс. Если таки хотите разрабатывать на руби — ставьте линукс (или покупайте мак )

вспомнился анекдот:
Приехал сын на деревню из армии. Утром собрались они с отцом за дровами. Идут значит с утра и отец решил сына расспросить об том как служба сейчас в современных войсках.
(О) — Ну ка сын, расскажи как там щас!
(С) — Хорошо отец щас на примере покажу. Вот мы идем за дровами — это «задача». А условия заданные командиром это «вводные». Так вот, (приближаясь они в речке которую надо по моту перейти), вводная — моста нет.
(О) — как нет?! Вот же он сына.
(С) — Я сказал что это вводная. Что моста нет. Это приказ и он не обсуждается.
(О) — Ладно сына, я понял. И что делать?!
(С) — что, что — задачу выполнять.
(О) — ну тогда в брод на телеге переберемся.

Нарубили они дров и только давай грузить на телегу,
(С) — новая вводная — телеги нет. Противник уничтожил транспорт авиа ударом.
(О) — как нет! Так вот же она. 🙁
(С) — я сказал же что это вводная.
__________________________________
В общем сам анекдот не важен как то что:
(ТС) — Задача, изучить Ruby. Вводные — есть инет и нетбук с Windows7 🙂 Денег на Мак нет, Люнекс для пренесет другие трудности, т.к. я его не знаю.

Читайте также:  Метод объекта windows js

EugenyT, вот вам пример, как с небольшими неудобствами работать с кирилическими литералами в windows (уверен, что найдутся лучшие способы, но для начала сгодится):

Как решить проблему с кодировкой в vagrant?

ACP это из древнегречeского ^W мелкомягкого такое важное слово из трех букв
https://knowledgebase.progress.com/articles/Articl.

может быть плохой идеей использовать поддержку национального языка в Vagrant, который AFAIK, который tries to be os independent .

UTF 8 это то что Ruby вероятно прожует зато Windows подавится.

для редактирования source of vagrant скрипта ничего особенно делать не надо надо только его найти:

это выполнено из гит баж

то же из под него родимого
— сохранил

У меня была аналогичная проблема и помогло решение со стека.

Конечно же Вы не нашли путь c:\HashiCorp\Vagrant\embedded\gems\gems\vagrant-1.6.3\bin\vagrant, так как у Вас версия vagrant 2.2.3 и соответственно путь: C:\HashiCorp\Vagrant\embedded\gems\2.2.3\gems\vagrant-2.2.3\bin\vagrant.

Чтобы отредактировать данный файл, я бы рекомендовал открыть его от имени администратора Windows в текстовом редакторе вроде Notepad++. Далее примерный перевод и копипаста:

1. Установите переменную окружения VAGRANT_HOME , например ‘c:\HashiCorp‘;
2. В файле C:\HashiCorp\Vagrant\embedded\gems\2.2.3\gems\vagrant-2.2.3\bin\vagrant после #!/usr/bin/env добавить две строки:

Важно Windows-1251, а не Windows-1250.
Думаю также может потребоваться перезагрузка для применения переменной окружения.

Vagrant Windows-1251 encoding error

I got the next error with vagrant when trying to use «vagrant up» command:

I have Windows 8.1, and I used «chcp 1251» command before, because it was the same error with «ibm866» encoding.

5 Answers 5

Problem was solved by setting environment variable VAGRANT_HOME

the solution for me was this one .

You have to go to : c:\HashiCorp\Vagrant\embedded\gems\gems\vagrant-1.6.3\bin\vagrant

And edit the vagrant (file) and put after this : #!/usr/bin/env ruby

Set an environtment variable VAGRANT_HOME to the path, for example ‘ c:\HashiCorp ‘

Then add to c:\HashiCorp\Vagrant\embedded\gems\gems\vagrant-1.6.3\bin\vagrant after #!/usr/bin/env ruby these two lines:

Notice Windows-1251 , not Windows-1250 .

And I think you might need to reboot to enable the environment variable.

Yes, setting environment variable VAGRANT_HOME can solve the problem.

I think it’s mainly because vagrant up command would try to visit %userprofile%\.vagrant.d folder, however, your %userprofile% is named in Windows 1251 encoding. Setting VAGRANT_HOME can point to a path recognizable for vagrant’s ruby script.

If you stil having some trouble with it, even after seting env variable, try just to move your «homestead» folder to a path that not contains any cyrilic symbols. Or you can create another user in you system without cyrilc Hope it helps!

Not the answer you’re looking for? Browse other questions tagged vagrant or ask your own question.

Hot Network Questions

Subscribe to RSS

To subscribe to this RSS feed, copy and paste this URL into your RSS reader.

site design / logo © 2021 Stack Exchange Inc; user contributions licensed under cc by-sa. rev 2021.4.16.39093

By clicking “Accept all cookies”, you agree Stack Exchange can store cookies on your device and disclose information in accordance with our Cookie Policy.

Problem Windows 8.1 incompatible character encodings: IBM866 and ASCII-8BIT #2763

Comments

ariutk commented Jan 5, 2014

D:\Dev\rails-dev-box-master>vagrant up
Bringing machine ‘default’ up with ‘virtualbox’ provider.
[default] Box ‘precise32’ was not found. Fetching box from specified URL for
the provider ‘virtualbox’. Note that if the URL does not have
a box for this provider, you should interrupt Vagrant now and add
the box yourself. Otherwise Vagrant will attempt to download the
full box prior to discovering this error.
Downloading box from URL: http://files.vagrantup.com/precise32.box
C:/HashiCorp/Vagrant/embedded/gems/gems/childprocess-0.3.9/lib/childprocess/wind
ows/process_builder.rb:63:in join’: incompatible character encodings: IBM866 an d ASCII-8BIT (Encoding::CompatibilityError) from C:/HashiCorp/Vagrant/embedded/gems/gems/childprocess-0.3.9/lib/chil dprocess/windows/process_builder.rb:63:in create_environment_pointer’
from C:/HashiCorp/Vagrant/embedded/gems/gems/childprocess-0.3.9/lib/chil
dprocess/windows/process_builder.rb:28:in start’ from C:/HashiCorp/Vagrant/embedded/gems/gems/childprocess-0.3.9/lib/chil dprocess/windows/process.rb:63:in launch_process’
from C:/HashiCorp/Vagrant/embedded/gems/gems/childprocess-0.3.9/lib/chil
dprocess/abstract_process.rb:72:in start’ from C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.4.2/lib/vagrant/u til/subprocess.rb:105:in block in execute’
from C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.4.2/lib/vagrant/u
til/safe_chdir.rb:26:in block (2 levels) in safe_chdir’ from C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.4.2/lib/vagrant/u til/safe_chdir.rb:25:in chdir’
from C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.4.2/lib/vagrant/u
til/safe_chdir.rb:25:in block in safe_chdir’ from C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.4.2/lib/vagrant/u til/safe_chdir.rb:24:in synchronize’
from C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.4.2/lib/vagrant/u
til/safe_chdir.rb:24:in safe_chdir’ from C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.4.2/lib/vagrant/u til/subprocess.rb:104:in execute’
from C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.4.2/lib/vagrant/u
til/subprocess.rb:24:in execute’ from C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.4.2/lib/vagrant/u til/downloader.rb:133:in block in download!’
from C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.4.2/lib/vagrant/u
til/busy.rb:19:in busy’ from C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.4.2/lib/vagrant/u til/downloader.rb:132:in download!’
from C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.4.2/lib/vagrant/a
ction/builtin/box_add.rb:191:in download_box_url’ from C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.4.2/lib/vagrant/a ction/builtin/box_add.rb:74:in block in call’
from C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.4.2/lib/vagrant/a
ction/builtin/box_add.rb:72:in each’ from C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.4.2/lib/vagrant/a ction/builtin/box_add.rb:72:in call’
from C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.4.2/lib/vagrant/a
ction/warden.rb:34:in call’ from C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.4.2/lib/vagrant/a ction/builder.rb:116:in call’
from C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.4.2/lib/vagrant/a
ction/runner.rb:69:in block in run’ from C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.4.2/lib/vagrant/u til/busy.rb:19:in busy’
from C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.4.2/lib/vagrant/a
ction/runner.rb:69:in run’ from C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.4.2/lib/vagrant/a ction/builtin/handle_box_url.rb:73:in block in call’
from C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.4.2/lib/vagrant/a
ction/builtin/handle_box_url.rb:56:in synchronize’ from C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.4.2/lib/vagrant/a ction/builtin/handle_box_url.rb:56:in call’
from C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.4.2/lib/vagrant/a
ction/warden.rb:34:in call’ from C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.4.2/lib/vagrant/a ction/warden.rb:95:in block in finalize_action’
from C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.4.2/lib/vagrant/a
ction/warden.rb:34:in call’ from C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.4.2/lib/vagrant/a ction/warden.rb:34:in call’
from C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.4.2/lib/vagrant/a
ction/builder.rb:116:in call’ from C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.4.2/lib/vagrant/a ction/runner.rb:69:in block in run’
from C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.4.2/lib/vagrant/u
til/busy.rb:19:in busy’ from C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.4.2/lib/vagrant/a ction/runner.rb:69:in run’
from C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.4.2/lib/vagrant/a
ction/builtin/call.rb:51:in call’ from C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.4.2/lib/vagrant/a ction/warden.rb:34:in call’
from C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.4.2/plugins/provi
ders/virtualbox/action/check_virtualbox.rb:17:in call’ from C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.4.2/lib/vagrant/a ction/warden.rb:34:in call’
from C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.4.2/lib/vagrant/a
ction/builder.rb:116:in call’ from C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.4.2/lib/vagrant/a ction/runner.rb:69:in block in run’
from C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.4.2/lib/vagrant/u
til/busy.rb:19:in busy’ from C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.4.2/lib/vagrant/a ction/runner.rb:69:in run’
from C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.4.2/lib/vagrant/m
achine.rb:147:in action’ from C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.4.2/lib/vagrant/b atch_action.rb:63:in block (2 levels) in run’

Читайте также:  Windows авторизация по протоколу

The text was updated successfully, but these errors were encountered:

ariutk commented Jan 5, 2014

Works if change the encoding of 1251. On another computer with the same version works with 866. 🙁

Ruby incompatible character encodings

I am currently trying to write a script that iterates over an input file and checks data on a website. If it finds the new data, it prints out to the terminal that it passes, if it doesn’t it tells me it fails. And vice versa for deleted data. It was working fine until the input file I was given contains the «™» character. Then when ruby gets to that line, it is spitting out an error:

PDAPWeb.rb:73:in `include?’: incompatible character encodings: UTF-8 and IBM437 (Encoding::CompatibilityError)

The offending line is a simple check to see if the text exists on the page.

Where the program_name variable is a parsed piece of information from the input file. In this instance, the program_name contains the ‘TM’ character mentioned before.

After some research I found that adding the line # encoding: utf-8 to the beginning of my script could help, but so far has not proven useful.

I added this to my program_name variable to see if it would help(and it allowed my script to run without errors), but now it is not properly finding the TM character when it should be.

This seemed to convert the TM character to this: Γäó

I thought maybe i had IBM437 and utf-8 parts reversed, so I tried the opposite

and am now receiving this error when attempting to run the script

PDAPWeb.rb:48:in `encode’: U+2122 from UTF-8 to IBM437 (Encoding::UndefinedConve rsionError)

I am using ruby 1.9.3p392 (2013-02-22) and I’m not sure if I should upgrade as this is the standard version installed in my company.

Читайте также:  Linux file delete all files

Is my encoding incorrect and causing it to convert the TM character with errors?

1 Answer 1

Here’s what it looks like is going on. Your input file contains a ™ character, and it is in UTF-8 encoding. However when you read it, since you don’t specify the encoding, Ruby assumes it is in your system’s default encoding of IBM437 (you must be on Windows).

This is basically the same as this:

Note that force_encoding doesn’t change the actual string, just the label associated with it. This is the same outcome as in your case, only you arrive here via a different route (by reading the file).

The web page also has a ™ symbol, and is also encoded as UTF-8, but in this case Ruby has the encoding correct (Watir probably uses the headers from the page):

Now when you try to compare these two strings you get the compatibility error, because they have different encodings:

If either of the two strings only contained ASCII characters (i.e. code points less that 128) then this comparison would have worked. Both UTF-8 and IBM437 are both supersets of ASCII, and are only incompatible if they both contain characters outside of the ASCII range. This is why you only started seeing this behaviour when the input file had a ™ .

The fix is to inform Ruby what the actual encoding of the input file is. You can do this with the already loaded string:

You can also do this when reading the file, e.g. (there are a few ways of reading files, they all should allow you to explicitly specify the encoding):

Note in both of these the string isn’t being changed, it still contains the same bytes, but Ruby now knows its correct encoding.

Now the comparison should work okay:

There is no need to encode the string. Here’s what happens if you do. First if you correct the encoding to UTF-8 then encode to IBM437:

IBM437 doesn’t include the ™ character, so you can’t encode a string containing it to this encoding without losing data. By default Ruby raises an exception when this happens. You can force the encoding by using the :undef option, but the symbol is lost:

If you go the other way, first using force_encoding to IBM437 then encoding to UTF-8 you get the string Γäó :

The string is already in IBM437 encoding as far as Ruby is concerned, so force_encoding doesn’t do anything. The UTF-8 representation of ™ is the three bytes 0xe2 0x84 0xa2 , and when interpreted as IBM437 these bytes correspond to the three characters seen here which are then converted into their UTF-8 representations.

(These two outcomes are the other way round from what you describe in the question, hence my comment above. I’m assuming that this is just a copy-and-paste error.)

Оцените статью
Adblock
detector