0

module 'urllib' has no attribute 'request'

Hello, i want to write a simple program for currency rate in ukraine bank, but i have some problem. Here is my code: import urllib import json import datetime def get_rate(currency): currencyname = currency.replace("/", "").upper() if currencyname not in listofcurrencies: answer = "Please, specify a currency name in a right way: \n /USD or \n /EUR or \n USD, EUR \n etc." return answer # https://bank.gov.ua/NBUStatService/v1/statdirectory/exchange?valcode=EUR&date=20181030&json todaydate = datetime.datetime.now().strftime("%Y%m%d") URL = 'https://bank.gov.ua/NBUStatService/v1/statdirectory/exchange?valcode=' + currencyname + '&date=' + todaydate + '&json' content = urllib.request.urlopen(URL) try: answer = f"NBU rate {currencyname} / UAH = {json.load(content)[0]['rate']} for today ({todaydate})" except IndexError: answer = "Something went wrong. Please try againe later" return answer listofcurrencies = ["AUD", "CAD", "CNY", "HRK", "CZK", "DKK", "HKD", "HUF", "INR", "IDR", "IRR", "ILS", "JPY", "KZT", "KRW", "MXN", "MDL", "NZD", "NOK", "RUB", "SAR", "SGD", "ZAR", "SEK", "CHF", "EGP", "GBP", "USD", "BYN", "AZN", "RON", "TRY", "XDR", "BGN", "EUR", "PLN", "DZD", "BDT", "AMD", "IQD", "KGS", "LBP", "LYD", "MYR", "MAD", "PKR", "VND", "THB", "AED", "TND", "UZS", "TWD", "TMT", "GHS", "RSD", "TJS", "GEL", "XAU", "XAG", "XPT", "XPD"] print(get_rate('AZN')) and here is python problem: Traceback (most recent call last): File "/Users/romanpetryshyn/PycharmProjects/untitled3/venv/lib/python3.8/Тато, задачі/Fun/1.py", line 24, in <module> print(get_rate('AZN')) File "/Users/romanpetryshyn/PycharmProjects/untitled3/venv/lib/python3.8/Тато, задачі/Fun/1.py", line 14, in get_rate content = urllib.request.urlopen(URL) AttributeError: module 'urllib' has no attribute 'request' tell me pls, what i need to do?

23rd Nov 2019, 12:43 PM
Олег Петришин
Олег Петришин - avatar
2 Answers
0
urllib is a folder not a file. And you can't import a folder but a file. request is a file inside urllib so use Import urllib.request
23rd Nov 2019, 2:44 PM
Mirielle
Mirielle - avatar
+ 1
Олег Петришин it's a old code for your reference: https://code.sololearn.com/cuH6516TmV5J/?ref=app edit:which was used here https://www.sololearn.com/Discuss/2017086/?ref=app and save your code and attach(link) here
23rd Nov 2019, 1:30 PM
Daljeet Singh
Daljeet Singh - avatar