简体   繁体   中英

OSError: [Errno 22] Invalid argument: requests

idle is giving this error:

Traceback (most recent call last):
  File "C:\.py", line 10, in <module>
    data_read = open(data)
OSError: [Errno 22] Invalid argument: 'line1\r\nline2\r\nline3

i tried to parse ini, json, yml allways the same error the code:

import requests

data = requests.get("https://pastebin.com/raw/R9cqXVYN").text

data_read = open(data)

while True:
    line = data_read.readline()
    if not line:
       break

    print(line.strip())

data_read.close

There's no point in having open(data) . That would work if, say, data was a path to a local file, but data is already text, so your code just needs to be:

import requests

data_read = requests.get("https://pastebin.com/raw/R9cqXVYN").text

for line in data_read.splitlines():
    print(line)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM