0

Here is my code.

import requests

url ='http://openapi.tago.go.kr/openapi/service/ExpBusArrInfoService/getExpBusTmnList'
data = {
'ServiceKey': u'....ZUH%2BuQNPmHiURbswJkYuWwM4UPzBZj3hQ%2FHafuEGG%2BujFqnf9rvZcodp4McovLUtrgc8rOBAPC3tNLQ%3D%3D',
'tmnNm': '서울'

I want to use restAPI, but when I request, the key which I put in tranformed like below.

print(http.url)
http://openapi.tago.go.kr/openapi/service/ExpBusArrInfoService/getExpBusTmnList?ServiceKey=Wpb3CsAZUH%252BuQNPmHiURbswJkYuWwM4UPzBZj3hQ%252FHafuEGG%252BujFqnf9rvZcodp4McovLUtrgc8rOBAPC3tNLQ%253D%253D&tmnNm=%EC%84%9C%EC%9A%B8

You might notice that it add 25 after '%' . So, request failed. How can I solve this problem? I guess formatting system maybe cause this trouble. But I dont know how fix it. Please help me.

toyaji
  • 83
  • 1
  • 8

1 Answers1

1

You tried to make a request using data already url-encoded. That's why your ServiceKey contains some %xx characters:

%2B means '+'
%3D means '='
etc.

You need to ensure the string used as service key is raw:

ZUH+uQNPmHiURbswJkYuWwM4UPzBZj3hQ/HafuEGG+ujFqnf9rvZcodp4McovLUtrgc8rOBAPC3tNLQ==

instead of

ZUH%2buQNPmHiURbswJkYuWwM4UPzBZj3hQ%2fHafuEGG%2bujFqnf9rvZcodp4McovLUtrgc8rOBAPC3tNLQ%3d%3d

There is a lot of resources on the internet to understand url encoding and decoding. For now, you can make sure your URL is raw by using an online URL encoder/decoder or simply use python API.

Antwane
  • 20,760
  • 7
  • 51
  • 84