1
import requests
data = 'C:\Users\abc\Desktop\dashboard\dom.html'
response = requests.get(data)
print (response.json())

Error receives as

SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated \UXXXXXXXX escape

I have tried making as data = (r'C:\Users\abc\Desktop\dashboard\dom.html') gives error as

requests.exceptions.InvalidSchema: No connection adapters were found for url
VietHTran
  • 2,233
  • 2
  • 9
  • 16
devpy77
  • 21
  • 1
  • I think the backslashes in the string might be the issue. Try adding `r` in front to make it a raw string. – AMC Feb 07 '20 at 03:48
  • You might want to look at https://stackoverflow.com/questions/15115328/python-requests-no-connection-adapters and https://stackoverflow.com/questions/1347791/unicode-error-unicodeescape-codec-cant-decode-bytes-cannot-open-text-file – xprilion Feb 07 '20 at 03:49
  • can't you simply read the data via reading file / – Juhil Somaiya Feb 07 '20 at 03:56
  • Isn't requests only for HTTP protocol? – revliscano Feb 07 '20 at 04:00

2 Answers2

0

Just change the type of slash. Replace it with this /. your code will become:

import requests
data = 'C:/Users/abc/Desktop/dashboard/dom.html'
response = requests.get(data)
print (response.json())
Behzad Jamali
  • 884
  • 2
  • 10
  • 23
Parikshit Singh
  • 167
  • 3
  • 4
0

You cannot read local files in requests, by default you can only use http or https protocols. However, you have the ability to write custom adapters, but the best way is to read the file normally instead of using requests.

with open("file.json") as fh:
    print(json.load(fh))