-
Notifications
You must be signed in to change notification settings - Fork 264
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
Prevent app from crashing #498
Conversation
print('Parsijoo parsed: ' + str(urls)) | ||
|
||
try: | ||
print('Parsijoo parsed: ' + str(urls)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I don't use try
except
block, I am getting error :
'charmap' codec can't encode characters in position 29-31: character maps to <undefined>
.
This error comes up when urls are empty.
It seems to be a console error rather than python as per statckoverflow . So handled this way.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks like encoding problem
@raju249 @realslimshanky let me know if app is now not crashing anyhow. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good Job 👏
app/scrapers/generalized.py
Outdated
@@ -42,8 +42,12 @@ def get_page(self, query, startIndex=0, qtype=''): | |||
if self.name == 'mojeek' and qtype == 'news': | |||
payload['fmt'] = 'news' | |||
response = requests.get(url, headers=self.headers, params=payload) | |||
status_code = response.status_code | |||
print(status_code) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove this statement. IMO, we can use logging to give detail logs on console. Let me know your opinion
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@vaibhavsingh97 I don't know about this logging
.(I thought print is only used to debug) Can you please point me to a link to read on this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
app/scrapers/generalized.py
Outdated
status_code = response.status_code | ||
print(status_code) | ||
if(status_code == 400 or status_code == 404): | ||
return (None, status_code) | ||
print(response.url) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same
if(len(urls) == 0): | ||
return (None, status_code) | ||
else: | ||
print("Couldn't fetch more results.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the case where, urls fetched are not equal to expected number of urls. Should not be removed from logs then in my opinion. As we have not implemented no. of urls fetched
yet.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not asking to remove this, I am asking to replace with logging statements
print('Parsijoo parsed: ' + str(urls)) | ||
|
||
try: | ||
print('Parsijoo parsed: ' + str(urls)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks like encoding problem
app/server.py
Outdated
@@ -36,11 +36,24 @@ def store(url, links): | |||
def index(): | |||
return render_template('index.html', engines_list=scrapers.keys()) | |||
|
|||
''' | |||
def bad_request(error): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this function doesn't handle the case of csv
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@vaibhavsingh97 can this be created as a separate issue for beginners. No case handling for csv too was present earlier. Should I open an issue for the same for beginners?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rupav Yes, That would be great and help beginner to solve the issue as well 👍
app/server.py
Outdated
return make_response(response, error[0]) | ||
print(error[2]) | ||
if error[2] == 'xml': | ||
print("Its XML!!!!!") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same
Will this will not create problem for other file types like |
@vaibhavsingh97 .No, regarding your query on adding a message corresponding to a given error, |
@rupav I am getting |
Ok, @vaibhavsingh97 looking into it. 👍 |
IMHO, a user-friendly message should be included on the client side like |
@realslimshanky This we can add as an enhancement and let beginner would solve that issue so from this atleast some new comer will join us and can join our awesome team 😄 |
@vaibhavsingh97 done (PS: https://travis-ci.org/fossasia/query-server/jobs/338069203 tests are failing because I introduced one more value to return 😅 i.e. status_code) These can be changed after this PR? |
@rupav It will better if you fix travis as well |
Ok @vaibhavsingh97 , so I have to change tests then. But one question. If I change tests in this PR, how can travis will be validating with new tests since new tests has not been merged 🤔? |
@rupav So what travis does is pull your commit and run tests present in your commit so if you change/add tests than travis will test those tests |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please check the travis report for your PR as many tests are failing.
yes @realslimshanky , since I introduces one more parameter, tests are failing. Looking into them 👍 |
60fec61
to
b469b4d
Compare
33fda7b
to
feeec13
Compare
@vaibhavsingh97 I solved almost all conflicts. had to comment out a test too (as it will always fail), |
Firstly it's not recommended to skip tests, especially when we are modifying the API. |
@@ -76,6 +77,7 @@ def test_api_search_for_no_response(mock_bad_request): | |||
mock_bad_request.assert_called_with([404, 'No response', | |||
'google:fossasia']) | |||
assert resp == "Mock Response" | |||
''' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@realslimshanky can you please see this test I skipped(commented out)...
test_api_searh_for_no_response
, why line 77 will ever be called? My point is why bad_request
function will be called when '/api/v1/search/google?query=fossasia'
fetches correct results, so it will not lead to calling up bad request. That's why this test will fail every time 😫
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, it is not testing for response from the server, it's testing the response already stored in catch. And since the request is made only once it's not present in cache.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So if not present in the cache, which code ideally should be executed, bad_request
should have been called ?
Which statements are we talking about here ... Please help. @realslimshanky
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have not worked with pytest/mock yet and would take some time to fully understand in order to assist you better. I would like to request contributors who have worked on this module to please help out.
cc: @vaibhavsingh97 @bhaveshAn
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@cclauss @bhaveshAn @vaibhavsingh97 please suggest.
Bing news is also crashing (Try : cricket) |
@rupav Status? |
@vaibhavsingh97 sorry for such a long delay, will get back to this, once I am through the documentation of pytest. I will update this as soon as I understand the problem ( which I raised earlier ). |
Closing this due to inactivity. Please reopen new PR if you want to resolve this. |
Fixes #494
Checklist
master
branch.Changes proposed in this pull request:
news
not implemented, yet is parsed, and creates a 400/404 error internally.https://aqueous-refuge-13068.herokuapp.com/
Few queries to look for:
search
chelsea
,friend
,local
or any other query ongoogle+news
andparsijoo+news
in both original http://query-server.herokuapp.com/ and https://aqueous-refuge-13068.herokuapp.com/ .