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

SSLV3_ALERT_HANDSHAKE_FAILURE when making requests to theforexapi.com #155

Open
KornelPudlo opened this issue Aug 29, 2024 · 0 comments
Open

Comments

@KornelPudlo
Copy link

I am using the forex_python library to convert currency values to USD using historical rates. However, I am encountering an SSL handshake failure when the library makes HTTPS requests to 'theforexapi.com'. The error message is as follows:

Error converting AUD for year 2022: HTTPSConnectionPool(host='theforexapi.com', port=443): Max retries exceeded with url: /api/2022-01-01?base=AUD&symbols=USD&rtype=fpy (Caused by SSLError(SSLError(1, '[SSL: SSLV3_ALERT_HANDSHAKE_FAILURE] sslv3 alert handshake failure (_ssl.c:997)')))

I have a csv file that contain multiple columns such as:
symbol, date, year, open, currency.

Currency columns contain values such as:
AUD, EUR, NZD, USD, GBP etc and trying to convert the $$$ from 'open' column to $USD based on a 'date' column.

Can someone try to help me? :)

Code below:

`
import pandas as pd
from forex_python.converter import CurrencyRates
from datetime import datetime

def convert_to_usd(row, c):
try:
# Constructing a date object with the year from the row and default month and day
date_obj = datetime(row['year'], 1, 1)
rate = c.get_rate(row['currency'], 'USD', date_obj)
return round(row['open'] * rate, 2)
except Exception as e:
print(f"Error converting {row['currency']} for year {row['year']}: {e}")
return None

def main():
# Load the CSV file
df = pd.read_csv('my_source_file_here_df.csv')

df['currency'] = df['currency'].str.strip().str.upper()

# Initialize currency converter
c = CurrencyRates()

# Convert prices to USD using historical rates
df['open_usd'] = df.apply(lambda row: convert_to_usd(row, c), axis=1)

# Save the updated dataframe to a new CSV file
df.to_csv('my_unpivoted_file_here_with_USD_df.csv', index=False)
print("Conversion completed and saved to 'converted_prices_with_historical_rates.csv'.")

if name == "main":
main()
`

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

No branches or pull requests

1 participant