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

UnicodeEncodeError: 'charmap' codec can't encode characters in position 2-13: character maps to <undefined> #25

Open
wan-andrea opened this issue Sep 2, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@wan-andrea
Copy link

wan-andrea commented Sep 2, 2024

I tried to use
instagram-location-search --lat 18.78 --lng 98.98 --csv locs.csv

But it throws an error whenever it tries to bring me to the login page for Instagram.

UnicodeEncodeError: 'charmap' codec can't encode characters in position 2-13: character maps to <undefined>
PS C:\Users\USER\downloads> instagram-location-search --lat 18.78 --lng 98.98 --csv locs.csv 

DevTools listening on ws://127.0.0.1:63333/devtools/browser/2ac137bc-ce41-4282-9c1b-bfa2566d473a
Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "C:\Users\USER\AppData\Local\Programs\Python\Python311\Scripts\instagram-location-search.exe\__main__.py", line 7, in <module>
  File "C:\Users\USER\AppData\Local\Programs\Python\Python311\Lib\site-packages\instagram_locations\instagram_locations.py", line 264, in main
    writer.writerow(row)
  File "C:\Users\USER\AppData\Local\Programs\Python\Python311\Lib\csv.py", line 154, in writerow
    return self.writer.writerow(self._dict_to_list(rowdict))
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\USER\AppData\Local\Programs\Python\Python311\Lib\encodings\cp1252.py", line 19, in encode
    return codecs.charmap_encode(input,self.errors,encoding_table)[0]
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@GalenReich GalenReich added the bug Something isn't working label Sep 3, 2024
@GalenReich
Copy link

Hi @wan-andrea, thanks for opening this issue! It looks like this is a bug where the response from Instagram contains a character that can't be written in the default encoding.

For developers, the relevant lines are:

with open(args.csv, "w") as f:
writer = csv.DictWriter(f, fieldnames=fieldnames)
writer.writeheader()
for idx, row in enumerate(locations):
row[""] = idx
writer.writerow(row)

Changing L259 to with open(args.csv, "w", encoding="utf-8") as f: may fix this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants