Hiikion
Hiikion

Reputation: 39

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

Upvotes: 0

Views: 1497

Answers (1)

Random Davis
Random Davis

Reputation: 6857

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)

Upvotes: 2

Related Questions