01/10/2018, 16:25

Thắc mắc về lỗi No JSON object could be decoded trong python

Chào mọi người !
Mình đang làm một bài tập về vệc kiểm tra tự động một danh sách các địa chỉ URL trên trang virus total. Nhưng khi mình chạy thì được một vài kết quả thì nó báo lỗi No JSON object could be decoded.
Mình ko biết là do đâu vì vậy nhờ mọi người chỉ giúp ah.

đây là dữ liệu trong file data.txt:

google.com
youtube.com
facebook.com
baidu.com

wikipedia.org

Wikipedia The Free Encyclopedia

This page is available under the Creative Commons Attribution-ShareAlike License Terms of Use Privacy Policy


reddit.com
Yahoo

Yahoo

News, email and search are just the beginning. Discover more every day. Find your yodel.


qq.com
amazon.com

Amazon.com: Online Shopping for Electronics, Apparel, Computers, Books, DVDs & more


taobao.com

Đây là code:

import time
import json
import sys
import urllib, urllib2
import requests
def check_VT(url):
    retrieve_url="https://www.virustotal.com/vtapi/v2/url/report"
    retrieve_parameters ={"resource":url, "apikey":""}
    #retrieve
    ret_data=urllib.urlencode(retrieve_parameters)
    ret_req=urllib2.Request(retrieve_url,ret_data)
    ret_response=urllib2.urlopen(ret_req)
    ret_json=ret_response.read()
    response_dict= json.loads(ret_json)
    #The idea here is that if any one scanning service lists the URL as malicious, we consider it as malicious
    if (('positives' in response_dict)==True):
        VT_result= response_dict['positives']
        if (VT_result >0 ): #if any one service says its malicious, then it is malicious
            status = "True"
        else:
            status = "False"
        return status
    else:
        status = "Not Found!!!"
        print status

with open('data.txt') as file:    
	for line in file:
		try:
			#line.strip('
')           
			VT_result = check_VT(line) #submit full_url to virustotal for checking
			print VT_result
		except Exception as ex:               
			print "Error: %s"%str(ex)
Quân viết 18:37 ngày 01/10/2018

The chosen format for the API is HTTP POST requests with JSON object responses and it is limited to at most 4 requests of any nature in any given 1 minute time frame.
https://www.virustotal.com/en/documentation/public-api/

Gửi bạn gì đó khi dùng public API thì đọc kĩ điều khoản và hướng dẫn sử dụng. Ngoài ra tự debug cũng là 1 cách tốt để nắm vững và liên kết các kiến thức từ đó dễ dàng tự giải quyết vấn đề mà không cần sự giúp đỡ từ bên ngoài

Bài liên quan
0