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

Issue: Specifying commod_codes in ct_search returns error. #27

Closed
amannj opened this issue Aug 18, 2020 · 3 comments
Closed

Issue: Specifying commod_codes in ct_search returns error. #27

amannj opened this issue Aug 18, 2020 · 3 comments

Comments

@amannj
Copy link
Contributor

amannj commented Aug 18, 2020

Hi,

I was trying to use comtradr to download some SITC Rev. 2 data on the 5-digit level. Here is what I did.

First, I update the database to SITC Rev.2

comtradr::ct_update_databases(commodity_type = "SITCrev2")

Running the following chunk of code works as expected.

comtradr::ct_search(reporters = "Mexico",
                                 partners  = "China",
                                 trade_direction = "exports",
                                 commod_codes = 'TOTAL')

However, as soon as I want to specify commod_codes I get the following error.

comtradr::ct_search(reporters = "Mexico",
                                 partners  = "China",
                                 trade_direction = "exports",
                                 commod_codes = "AG5")

Error: API did not return json. Instead, text/html data was returned

I observe this behaviour for AG[X], X = 1,...,5. I'm running comtradr version 0.2.2.

Thanks a lot for your help.

@ChrisMuir
Copy link
Member

Hello, thanks for bringing this to my attention. I played around with this a bunch, the issues seems to be that, when using SITC Rev.2, the API url args head and fmt (see here) are in such an order that it's causing the API to return a chunk of HTML back as the response. The HTML being returned looks like this:

<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8"/>
    <title>UN Comtrade | International Trade Statistics Database</title>
    <meta name="DESCRIPTION" content="United Nations Comtrade Database - International Trade Statistics - Import/Export Data" />
    <meta name="KEYWORDS" content="trade, trade data, imports, exports, world trade, international trade, trade statistics, commodity, merchandise, goods, services, trade in services, merchandise trade, comtrade, comtrade database" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
    <!--<link href="css/bootstrap.min.css" rel="stylesheet" media="screen">-->
	 <link href="https://comtrade.un.org/css/bootstrap-3.3.7.min.css" rel="stylesheet" media="screen"/>
    <link href="css/bootstrap-responsive.min.css" rel="stylesheet" media="screen"/>
    <link rel="stylesheet" href="css/owl.carousel/owl.car

When I flip the order of the head and fmt args in the url creation step, it seems to alleviate the issue, I'm now getting data back on the "AGx" queries.

I just pushed a fix to branch sitc-bug. Can you try installing from that new branch, and then re-running your queries? You can use this to install the branch:

require(remotes)
remotes::install_github("ropensci/comtradr", ref = "sitc-bug")

@amannj
Copy link
Contributor Author

amannj commented Oct 5, 2020

Hi, thanks a lot.

Just installed the new branch and re-ran the queries from my bug report for AG[X], X = 1,...,5, and it went through with no further hick-ups.

@ChrisMuir
Copy link
Member

Bug fixed in commit 97c2ee1.

ChrisMuir added a commit that referenced this issue Nov 26, 2021
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

2 participants