Python으로 ix.io에 데이터 올리기

2022. 9. 30. 21:46·python snippets
import requests

with open("test.json", "r", encoding="utf-8") as f:
    data = f.read()
req = requests.post("http://ix.io", files={"f:1": data})
print(f"json 테스트: {req.content.decode('utf-8').strip()}")

strdata = "테스트 데이터입니다."
req = requests.post("http://ix.io", files={"f:1": strdata})
print(f"일반 텍스트 테스트: {req.content.decode('utf-8').strip()}")


출력:
>>> json 테스트: http://ix.io/4bU0
>>> 일반 텍스트 테스트: http://ix.io/4bU1

 

requests 모듈 이용

requests.post("http://ix.io", files={"f:1": 넣고 싶은 데이터}) 형식으로 보내면 됨

링크 받아올 땐 content부분을 보면 되며,

bytes 형식이니 decode를 해주면 좋음

개행문자까지 리턴되니까 .strip()을 사용하면 더 보기 깔끔해짐

 

 

 

new_dict = {...}
with open("test.json", "w", encoding="utf-8") as f:
    json.dump(new_dict, f, ensure_ascii=False, separators=(",", ":"))
    
with open("test2.json", "r", encoding="utf-8") as f:
    data = json.load(f)
    data = json.dumps(data, ensure_ascii=False, separators=(",", ":"))

dict 데이터를 보낼 떈 위와 같이 separators 파라미터를 이용하면 용량이 확 줄어서 괜찮은 것 같음

저작자표시 비영리 변경금지 (새창열림)

'python snippets' 카테고리의 다른 글

Python 3.12에서 ImportError: No module named matplotlib 에러가 뜰 때  (1) 2023.10.27
Python으로 문자 일괄치환  (0) 2023.09.30
Python으로 Google Sheets에 있는 csv 사용하기  (0) 2023.09.29
'python snippets' 카테고리의 다른 글
  • Python 3.12에서 ImportError: No module named matplotlib 에러가 뜰 때
  • Python으로 문자 일괄치환
  • Python으로 Google Sheets에 있는 csv 사용하기
Snowyegret
Snowyegret
기록용 블로그입니다.
  • Snowyegret
    Snowyegret
    Snowyegret
  • 공지사항

    • 문의: 디스코드 snowyegret12
    • 연락처(디스코드) 계정 변경 안내
    • 블로그 운영 재개 안내
  • 링크

    • 블로그 메인
    • 방명록/문의사항
    • Github Repositories
    • Github Gists
    • 분류 전체보기 (86) N
      • 늑대와 향신료 VR2 한글패치 (1)
      • 장난을 잘 치는 타카기양 VR 1학기 한글패치 (1)
      • Shephy 카드 설명 한국어 텍스쳐 모드 (1)
      • 한글패치 관련 짧은 글들 (37)
      • 한글패치 작업 내역 (11)
      • 한글화 분석 (작업X) (5)
      • python snippets (4)
      • 게임 (2)
      • 간단프로그램 (2)
      • IT (17)
      • TODO (2)
  • 인기 글

  • 최근 글

  • 최근 댓글

  • hELLO· Designed By정상우.v4.10.5
Snowyegret
Python으로 ix.io에 데이터 올리기
상단으로

티스토리툴바