Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix KeyError #237

Closed
wants to merge 1 commit into from
Closed

Fix KeyError #237

wants to merge 1 commit into from

Conversation

mzfr
Copy link
Collaborator

@mzfr mzfr commented Feb 24, 2020

Fixes #201

There was no hash key in the /status_404. Instead, that key is present in /index.html

{'/index.html': {'hash': 'd1546d731a9f30cc80127d57142a482b', 'content_type': 'text/html'}, '/status_404': {}}

So I fixed that and now snare starts properly.

@adepasquale
Copy link
Member

SnareMiddleware constructor requires the 1st param to be the filename of the HTTP 404 page, so that's not meant to be changed.

@mzfr
Copy link
Collaborator Author

mzfr commented Feb 25, 2020

okay so how do you suggest we tackle that issue?
As we can see in value of self.meta I posted above the /status_404 key has no values in the dictionary.

Should we add just put that code between a try & catch block?

@adepasquale
Copy link
Member

What clone command did you run in order to generate a meta.json without that /status_404 key?

@mzfr
Copy link
Collaborator Author

mzfr commented Feb 25, 2020

I used sudo clone --target example.com

@mzfr
Copy link
Collaborator Author

mzfr commented Feb 26, 2020

so I tested it again with the same command sudo clone --target example.com and now there was hash key in the status_404. So not really sure why this might be happening.

But still the good practice would be to just put this statement in a try & except block.

we can do something like:

try:
	  middleware = SnareMiddleware(
           self.meta['/status_404']['hash'],
           self.run_args.server_header
        )
except KeyError:
	print_color("No hash value found for 404 page", ERROR)
	print_color("Please try to clone the page/website again", INFO) 

@afeena @adepasquale what are your thoughts about it?

@afeena
Copy link
Collaborator

afeena commented Mar 1, 2020

@mzfr I think it would be better to make a validation function to make sure that provided page has needed meta info

@mzfr
Copy link
Collaborator Author

mzfr commented Mar 1, 2020

Ok then I'll implement validation function ASAP

@mzfr mzfr mentioned this pull request Mar 2, 2020
@afeena
Copy link
Collaborator

afeena commented Mar 3, 2020

Since suggested changes made in #251, closed

@afeena afeena closed this Mar 3, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

KeyError 'hash' / 'Value' whle running `snare --port 8080 --page-dir "some site name"
3 participants