0

I am newbie in python and i am trying to open an localhost with write mode but i got following errors

with io.open('http:\\localhost:3000\\assets\\i18n\\locale-ru.json', 'w') as outfile:

IOError: [Errno 22] Invalid argument: 'http:\\localhost:3000\\assets\\i18n\\locale-ru.json'

Here is a piece of code:

 with io.open('http://localhost:3000//assets//i18n//locale-ru.json', 'w') as outfile:
  str_ = json.dumps(data_ru,
                    indent=4, sort_keys=True,
                    separators=(',', ': '), ensure_ascii=False)
  outfile.write(to_unicode(str_))
vencaslac
  • 2,727
  • 1
  • 18
  • 29
user987
  • 1
  • 6

1 Answers1

0

According to the doc, the io.open function only reads a local file given a file path. Considering you're trying to read from a http url, I guess a better tools might be requests

Old Panda
  • 1,466
  • 2
  • 15
  • 30
  • getting struggle with reguests documentation, i would really appreciate if you send me with source code – user987 Nov 12 '18 at 20:10
  • what about urllib.urlopen in Python 2.7 – user987 Nov 13 '18 at 11:24
  • ` with urllib.urlopen('http://localhost:3000//assets/i18n//locale-kg.json', 'w') as outfile: str_ = json.dumps(data_kg, indent=4, sort_keys=True, separators=(',', ': '), ensure_ascii=False) outfile.write(to_unicode(str_))` – user987 Nov 13 '18 at 11:25
  • As far as I know, to update a file via HTTP you have to send a POST or a PUT request with a file on your local, just like you upload a file to some website. So if I wanted to update a file via an URL, I would firstly download it to my local, then do changes on it, and finally upload the file back. As for file uploading, you could refer https://stackoverflow.com/a/26791188/2191173 for details. – Old Panda Nov 13 '18 at 18:26