question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Get the data as response from URL report

See original GitHub issue

Here is the code

import vt
client = vt.Client(<API KEY>)
analysis = client.scan_url('https://21stcenturywire.com/2021/04/07/texas-governor-signs-order-banning-use-of-vaccine-passports/', wait_for_completion=True)
print(analysis)

Output

analysis u-17cca8a680d8c2b04a044cc689cdb2dadde2b43abcc2edfe290f3cb552d49bbe-1619945963
Unclosed client session
client_session: <aiohttp.client.ClientSession object at 0x0000017280919610>
Unclosed connector
connections: ['[(<aiohttp.client_proto.ResponseHandler object at 0x0000017280944220>, 6975.046)]']
connector: <aiohttp.connector.TCPConnector object at 0x0000017280919430>

But I want the result in terms of JSON to be added to my streamlit web app : https://developers.virustotal.com/reference#url-report

{
 'response_code': 1,
 'verbose_msg': 'Scan finished, scan information embedded in this object',
 'scan_id': '1db0ad7dbcec0676710ea0eaacd35d5e471d3e11944d53bcbd31f0cbd11bce31-1390467782',
 'permalink': 'https://www.virustotal.com/url/__urlsha256__/analysis/1390467782/',
 'url': 'http://www.virustotal.com/',
 'scan_date': '2014-01-23 09:03:02',
 'filescan_id': null,
 'positives': 0,
 'total': 51,
 'scans': {
    'CLEAN MX': {
      'detected': false, 
      'result': 'clean site'
    },
    'MalwarePatrol': {
      'detected': false, 
      'result': 'clean site'
    }
  }
}

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

3reactions
mgmacias95commented, May 2, 2021

Hello @hritik5102,

Try doing

import vt
client = vt.Client(os.environ.get('VIRUS_TOTAL_API_KEY'))
analysis = await client.scan_url_async('https://21stcenturywire.com/2021/04/07/texas-governor-signs-order-banning-use-of-vaccine-passports/', wait_for_completion=True)
result =  analysis.to_dict() 

or

import vt
client = vt.Client(os.environ.get('VIRUS_TOTAL_API_KEY'))
analysis = client.scan_url('https://21stcenturywire.com/2021/04/07/texas-governor-signs-order-banning-use-of-vaccine-passports/', wait_for_completion=True)
result =  analysis.to_dict() 

The _async method use case would be launching multiple analyses in parallel and then fetching their results, something like this:

urls_to_scan = ['https://www.google.com/', 'https://www.virustotal.com/', 'https://github.com/']
futures = [client.scan_url_async(u) for u in urls_to_scan]
# do some other work here
for f in futures:
  result = await f
  print(result.to_dict())

If you’re only analysing one URL, using scan_url vs scan_url_async has (almost) no performance improvements I’d say.

Take in mind await should be used inside async functions, to learn more check out the python docs

I hope this helps.

Regards, Marta

1reaction
mgmacias95commented, May 2, 2021

Hello @hritik5102,

Once you have your analysis object (returned from scan_url function) you can use its to_dict method:

analysis.to_dict()

I hope this helps.

Regards, Marta

Read more comments on GitHub >

github_iconTop Results From Across the Web

Export a Report Using URL Access - SQL - Microsoft Learn
Learn how to export a report using URL access by specifying the format in which to render a report by using the rs:Format...
Read more >
Response.url - Web APIs | MDN
The url read-only property of the Response interface contains the URL of the response. The value of the url property will be the...
Read more >
Generate Report via URL and GET request - python
However, I can't get the response object to be the report itself and subsequently, can't get the report as a Data Frame. Unfortunately...
Read more >
response.url - Python requests - GeeksforGeeks
response.url returns the URL of the response. It will show the main url which has returned the content, after all redirections, if done....
Read more >
How To Use the JavaScript Fetch API to Get Data - DigitalOcean
The response parameter takes the value of the object returned from fetch(url) . Use the json() method to convert response into JSON data:....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found