0
import urllib.request
import time
import json
import random

QUERY = "http://localhost:8080/query?id={}"
N = 500

def getDataPoint(quote):
    stock = quote['stock']
    bid_price = float(quote['top_bid']['price'])
    ask_price = float(quote['top_ask']['price'])
    price = (bid_price + ask_price)/2
    return stock, bid_price, ask_price, price

def getRatio(price_a, price_b):
    if(price_b==0):
        return
    return price_a/price_b

if __name__ == "__main__":
    for _ in range(N):
        quotes = json.loads(urllib.request.urlopen( 
        QUERY.format(random.random())).read())
        prices = {}
        for quote in quotes:
            stock, bid_price, ask_price, price = getDataPoint(quote)
            prices[stock] = price
            print ("Quoted %s at (bid:%s, ask:%s, price:%s)" % (stock, 
            bid_price, ask_price, price))

        print ("Ratio %s" % getRatio(prices['ABC'], prices['DEF']))

Traceback (most recent call last): File "C:/Users/AppData/Local/Programs/Python/Python37/ client.py", line 54, in quotes= json.loads(urllib.request.urlopen(QUERY.format(random.random())).read()) File "C:\Users\AppData\Local\Programs\Python\Python37\lib\urllib\request.py", line 222, in urlopen return opener.open(url, data, timeout) File "C:\Users\AppData\Local\Programs\Python\Python37\lib\urllib\request.py", line 531, in open response = meth(req, response) File "C:\Users\AppData\Local\Programs\Python\Python37\lib\urllib\request.py", line 641, in http_response 'http', request, response, code, msg, hdrs) File "C:\Users\AppData\Local\Programs\Python\Python37\lib\urllib\request.py", line 569, in error result = self._call_chain(*args) File "C:\Users\AppData\Local\Programs\Python\Python37\lib\urllib\request.py", line 503, in _call_chain result = func(*args) File "C:\Users\AppData\Local\Programs\Python\Python37\lib\urllib\request.py", line 649, in in http_error_default raise HTTPError(req.full_url, code, msg, hdrs, fp) urllib.error.HTTPError: HTTP Error 404: Not Found

I've error with the URL.Did some research and tried to clear still not so sure why the client part throws error while server part works fine.

3
  • 1
    Did you run your program in a debugger? It'd probably lead you to the exact line of code that's triggering the undefined behavior. Commented Aug 5, 2020 at 18:00
  • Can you help resolving the above issue? Commented Aug 6, 2020 at 6:03
  • You completely changed this from a question about C++ to a question about python. Why didn't you just ask a new question? Commented Aug 6, 2020 at 12:28

2 Answers 2

0

This is caused due to the firewall of your computer blocking port 8080. Change the port from 8080 to say 8085 in both the client and server files.

In the above code, Change QUERY = "http://localhost:8080/query?id={}" To QUERY = "http://localhost:8085/query?id={}"

Similarly, there should be 8080 as the port number in the server file, change it to 8085.

Another solution would be to disable your firewall, which is not recommended.

Sign up to request clarification or add additional context in comments.

Comments

0

Simply say, your server application is not running in the said location: http://localhost:8080/query

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.