2017-11-12 7 views
-1

계속 오류 메시지가 표시됩니다. 하나의 영화 API를 사용하려고합니다. 몇 시간 후에 문제를 해결하려고했습니다. 나는 URL의 우편 번호 입력을 변경하면 모든 것이 잘 진행하지만 코드는 30080와 30434입니다에 차이가 ....ValueError : ','delimiter가 필요함

`{"meta_info": {"range_to": 14, "total_count": 15, "range_from": 0}, "movies": [{"title": "Paddington 2", "poster_image_thumbnail": "", "slug": "paddington-2", "id": "24544"}, {"title": "Justice League", "poster_image_thumbnail": "", "slug": "justice-le 
ague", "id": "25378"}, {"title": "Murder on the Orient Express", "poster_image_thumbnail": "", "slug": "mord-im-orient-express 
", "id": "6317"}, {"title": "Thor: Ragnarok", "poster_image_thumbnail": "", "slug": "thor-ragnarok", "id": "12218"}, {"title": 
"A Bad Moms Christmas", "poster_image_thumbnail": "", "slug": "a-bad-moms-christmas", "id": "26438"}, {"title": "Daddy"s Home 
2", "poster_image_thumbnail": "", "slug": "daddy-s-home-2", "id": "28203"}, {"title": "Jigsaw", "poster_image_thumbnail": "ht 
tp://image.tmdb.org/t/p/w154/zUbUtxiTdEgWnkXY945gtYYqBZ1.jpg", "slug": "saw-legacy", "id": "24657"}, {"title": "The Death of Stalin", "poster_image_thumbnail": "", "slug": "the-death-of-stalin", "id": "26537"}, {"title": "The LEGO Ninjago Movie", "poster_image_thumbnail": "http://image.tmdb.org/t/p/w154/uJhKcWL2G 
fqIh0W17JBnzlER9oh.jpg", "slug": "lego-ninjago", "id": "12166"}, {"title": "My Little Pony: The Movie", "poster_image_thumbnail": " 
X.jpg", "slug": "my-little-pony-the-movie", "id": "24216"}, {"title": "Breathe", "poster_image_thumbnail": "", "slug": "breath 
e", "id": "21244"}, {"title": "Blade Runner 2049", "poster_image_thumbnail": "", "slug": "blade-runner-2", "id": "12664"}, {"t 
itle": "The Jungle Bunch", "poster_image_thumbnail": "http://image.tmdb.org/t/p/w154/771CzGEt3sforEIBuVliKfQz7Md.jpg", "slug": "les-as-de-la-jungle", "id": "29613"}, {"title": "Logan Lucky 
", "poster_image_thumbnail": "", "slug": "logan-lucky", "id": "24384"}, {"title": "The Exterminating Angel: Met Opera Live", " 
poster_image_thumbnail": "Null", "slug": "the-exterminating-angel-met-opera-live", "id": "31222"}]} 

    Traceback (most recent call last): 
    File "test222.py", line 35, in <module> 
    showtime() 
    File "test222.py", line 24, in showtime 
    data = json.loads(response_one) 
    File "/usr/lib/python3.4/json/__init__.py", line 318, in loads 
    return _default_decoder.decode(s) 
    File "/usr/lib/python3.4/json/decoder.py", line 343, in decode 
    obj, end = self.raw_decode(s, idx=_w(s, 0).end()) 
    File "/usr/lib/python3.4/json/decoder.py", line 359, in raw_decode 
    obj, end = self.scan_once(s, idx) 
ValueError: Expecting ',' delimiter: line 1 column 935 (char 934) 

일부 내 코드가 해주된다

def showtime(): 
cinemaID = "30181" 
try: 
    response = requests.get(
     url="https://api.internationalshowtimes.com/v4/movies/?cinema_id=" + cinemaID, 
     params={ 
      "countries": "GB", 
     }, 
     headers={ 
      "X-API-Key": "***", 
     }, 
    ) 
    countnew = 0 
    limitnew = 3 
    response = str(response.json()) 
    response_one = str(response.replace("'", '"')) 
    response_one = str(response_one.replace("None", '"Null"')) 
    print(response_one) 
    data = json.loads(response_one) 
    for item in data['movies']: 
     print (str(countnew+1),".","Title:","",item['title'],"\n"," ","Image:","",item['poster_image_thumbnail']) 
     print(" ") 
     time.sleep(0.8) 
     countnew += 1 
     if countnew == limitnew: 
      break 

except requests.exceptions.RequestException: 
    print('HTTP Request failed') 

쇼 타임()

+0

실행 JSON과 같은 큰 따옴표를 이스케이프해야합니다 .. – user2864740

+0

당신은 볼 수 있습니다; 아포스트로피보다는 이중 따옴표가있는 "아빠의 집 2"의 중간에 있습니다. –

+0

나는 그것을했다. 이상한 점은 cinemaID를 30484로 변경하면 코드가 작동하지만 30080로 다시 변경하면 오류가 발생합니다. –

답변

1

여기에 "이 있습니다. "title": "Daddy"sHome2"입니다. 이 변화를 강조 구문으로, 잘못되는 곳

온라인으로 볼과 같이하는 JSON의 보풀/검증을 통해이 "title": "Daddy\"sHome2"

+0

코드에서 어떻게 할 수 있습니까? –

+0

코드에서'item [ 'title']'을'item [ 'title']로 바꿉니다. replace (' "' ''") " – JLo

+0

아니요, 여전히 나에게 같은 오류 메시지를줍니다 ... –