{"html_url": "https://github.com/simonw/sqlite-utils/issues/448#issuecomment-1539109816", "issue_url": "https://api.github.com/repos/simonw/sqlite-utils/issues/448", "id": 1539109816, "node_id": "IC_kwDOCGYnMM5bvPO4", "user": {"value": 9599, "label": "simonw"}, "created_at": "2023-05-08T22:01:00Z", "updated_at": "2023-05-08T22:01:00Z", "author_association": "OWNER", "body": "This is being handled in:\r\n- #520", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 1279144769, "label": "Reading rows from a file => AttributeError: '_io.StringIO' object has no attribute 'readinto'"}, "performed_via_github_app": null} {"html_url": "https://github.com/simonw/sqlite-utils/issues/448#issuecomment-1297703307", "issue_url": "https://api.github.com/repos/simonw/sqlite-utils/issues/448", "id": 1297703307, "node_id": "IC_kwDOCGYnMM5NWWGL", "user": {"value": 167893, "label": "mcarpenter"}, "created_at": "2022-10-31T21:23:51Z", "updated_at": "2022-10-31T21:27:32Z", "author_association": "CONTRIBUTOR", "body": "The Windows aspect is a red herring: OP's sample above produces the same error on Linux. (Though I don't know what's going on with the CI).\r\n\r\nThe same error can also be obtained by passing an `io` from a file opened in non-binary mode (`'r'` as opposed to `'rb'`) to `rows_from_file()`. This is how I got here.\r\n\r\nThe fix for my case is easy: open the file in mode `'rb'`. The analagous fix for OP's problem also works: use `BytesIO` in place of `StringIO`.\r\n\r\nMinimal test case (derived from [utils.py](https://github.com/simonw/sqlite-utils/blob/main/sqlite_utils/utils.py#L304)):\r\n\r\n``` python\r\nimport io\r\nfrom typing import cast\r\n\r\n#fp = io.StringIO(\"id,name\\n1,Cleo\") # error\r\nfp = io.BytesIO(bytes(\"id,name\\n1,Cleo\", encoding='utf-8')) # okay\r\nreader = io.BufferedReader(cast(io.RawIOBase, fp))\r\nreader.peek(1) # exception thrown here\r\n```\r\nI see the signature of `rows_from_file()` correctly has `fp: BinaryIO` but I guess you'd need either a runtime type check for that (not all `io`s have `mode()`), or to catch the `AttributeError` on `peek()` to produce a better error for users. Neither option is ideal.\r\n\r\nSome thoughts on testing binary-ness of `io`s in this SO question: https://stackoverflow.com/questions/44584829/how-to-determine-if-file-is-opened-in-binary-or-text-mode", "reactions": "{\"total_count\": 2, \"+1\": 2, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 1279144769, "label": "Reading rows from a file => AttributeError: '_io.StringIO' object has no attribute 'readinto'"}, "performed_via_github_app": null} {"html_url": "https://github.com/simonw/sqlite-utils/issues/448#issuecomment-1186002560", "issue_url": "https://api.github.com/repos/simonw/sqlite-utils/issues/448", "id": 1186002560, "node_id": "IC_kwDOCGYnMM5GsPaA", "user": {"value": 9599, "label": "simonw"}, "created_at": "2022-07-15T22:40:40Z", "updated_at": "2022-07-15T22:40:40Z", "author_association": "OWNER", "body": "This is very strange. GitHub Actions CI here runs against Windows and installs OK.\r\n\r\nMarking this as \"Help wanted\" to see if anyone can figure out what's going on here.", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 1279144769, "label": "Reading rows from a file => AttributeError: '_io.StringIO' object has no attribute 'readinto'"}, "performed_via_github_app": null} {"html_url": "https://github.com/simonw/sqlite-utils/issues/448#issuecomment-1162500525", "issue_url": "https://api.github.com/repos/simonw/sqlite-utils/issues/448", "id": 1162500525, "node_id": "IC_kwDOCGYnMM5FSlmt", "user": {"value": 236907, "label": "mungewell"}, "created_at": "2022-06-22T00:46:43Z", "updated_at": "2022-06-22T00:46:43Z", "author_association": "NONE", "body": "[log.txt](https://github.com/simonw/sqlite-utils/files/8953589/log.txt)\r\n", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 1279144769, "label": "Reading rows from a file => AttributeError: '_io.StringIO' object has no attribute 'readinto'"}, "performed_via_github_app": null} {"html_url": "https://github.com/simonw/sqlite-utils/issues/448#issuecomment-1162498734", "issue_url": "https://api.github.com/repos/simonw/sqlite-utils/issues/448", "id": 1162498734, "node_id": "IC_kwDOCGYnMM5FSlKu", "user": {"value": 236907, "label": "mungewell"}, "created_at": "2022-06-22T00:43:45Z", "updated_at": "2022-06-22T00:43:45Z", "author_association": "NONE", "body": "Attempted to test on a machine with a new version of Python, but install failed with an error message for the 'click' package.\r\n\r\n```\r\nC:\\WINDOWS\\system32>\"c:\\Program Files\\Python310\\python.exe\"\r\nPython 3.10.2 (tags/v3.10.2:a58ebcc, Jan 17 2022, 14:12:15) [MSC v.1929 64 bit (AMD64)] on win32\r\nType \"help\", \"copyright\", \"credits\" or \"license\" for more information.\r\n>>> quit()\r\n\r\nC:\\WINDOWS\\system32>cd C:\\Users\\swood\\Downloads\\sqlite-utils-main-20220621\\sqlite-utils-main\r\n\r\nC:\\Users\\swood\\Downloads\\sqlite-utils-main-20220621\\sqlite-utils-main>\"c:\\Program Files\\Python310\\python.exe\" setup.py install\r\nrunning install\r\nrunning bdist_egg\r\nrunning egg_info\r\n\r\n...\r\n\r\nInstalled c:\\program files\\python310\\lib\\site-packages\\click_default_group_wheel-1.2.2-py3.10.egg\r\nSearching for click\r\nDownloading https://files.pythonhosted.org/packages/3d/da/f3bbf30f7e71d881585d598f67f4424b2cc4c68f39849542e81183218017/click-default-group-wheel-1.2.2.tar.gz#sha256=e90da42d92c03e88a12ed0c0b69c8a29afb5d36e3dc8d29c423ba4219e6d7747\r\nBest match: click default-group-wheel-1.2.2\r\nProcessing click-default-group-wheel-1.2.2.tar.gz\r\nWriting C:\\Users\\swood\\AppData\\Local\\Temp\\easy_install-aiaj0_eh\\click-default-group-wheel-1.2.2\\setup.cfg\r\nRunning click-default-group-wheel-1.2.2\\setup.py -q bdist_egg --dist-dir C:\\Users\\swood\\AppData\\Local\\Temp\\easy_install-aiaj0_eh\\click-default-group-wheel-1.2.2\\egg-dist-tmp-z61a4h8n\r\nzip_safe flag not set; analyzing archive contents...\r\nremoving 'c:\\program files\\python310\\lib\\site-packages\\click_default_group_wheel-1.2.2-py3.10.egg' (and everything under it)\r\nCopying click_default_group_wheel-1.2.2-py3.10.egg to c:\\program files\\python310\\lib\\site-packages\r\nclick-default-group-wheel 1.2.2 is already the active version in easy-install.pth\r\n\r\nInstalled c:\\program files\\python310\\lib\\site-packages\\click_default_group_wheel-1.2.2-py3.10.egg\r\nerror: The 'click' distribution was not found and is required by click-default-group-wheel, sqlite-utils\r\n```", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 1279144769, "label": "Reading rows from a file => AttributeError: '_io.StringIO' object has no attribute 'readinto'"}, "performed_via_github_app": null}